Pinterest API - pure json response?

无人久伴 提交于 2019-12-12 08:57:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!