For a URL I am trying to count it’s tweets through this API request:
http://urls.api.twitter.com/1/urls/count.json?url=http://www.bbc.co.uk
This (in a Browser) returns the following Json:
{"count":216743,"url":"http:\/\/www.bbc.co.uk\/"}
I can manually parse the response:
$tweets = json_decode('{"count":216743,"url":"http:\/\/www.bbc.co.uk\/"}');
$this->set('tweets', $tweets->{'count'});
When I enter the URL instead of the Json, it doesn’t request any data. How would I get the following to work?
$tweets = json_decode('http://urls.api.twitter.com/1/urls/count.json?url=http://www.bbc.co.uk');
$this->set('tweets', $tweets->{'count'});
json_decodeexpects to get a JSON string.http://urls.api.twitter.com/1/urls/count.json?url=http://www.bbc.co.ukis not a JSON string, it’s a URL.json_decodedoes not fetch URLs. You need to fetch the URL yourself, then pass the result tojson_decode: