问题
So I made a simple HTTP request to Pinterest's API to get the count of a link:
$this->load->library('rest');
$this->rest->initialize(array('server' => 'http://api.pinterest.com/'));
$return_data = $this->rest->get('v1/urls/count.json?callback=&url=' . $link);
The response I get is:
receiveCount({"count": 5743, "url": "http://google.com"})
You can try this yourself here.
I don't want the callback and I tried setting callback=
but the parenthesis are still present so I can't parse it via json_decode
.
Is there a better way of getting a pure json response without having to string replace the parenthesis myself?
回答1:
The Pintrest API is currently in development and is not ready for public use; they removed their own documentation a while ago. There is however a cache on Bolt for v2 of the API.
For now I would just do a regex on the response such as
$return_data = preg_replace('/^receiveCount\((.*)\)$/', "\\1", $return_data);
And then json_decode
that.
来源:https://stackoverflow.com/questions/11647809/pinterest-api-pure-json-response