Hi there,
I am using curl to output counts of various social media likes etc. I have successfully used the code below for Facebook and Twitter but am struggling to get the value of an Instagram count for a specific hashtag.
The code I have been using (twitter shares example) is:
$ch = curl_init("https://cdn.api.twitter.com/1/urls/count.json?url=http://www.1millionmilesforellie.co.uk");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$sure = curl_exec($ch);
curl_close($ch);
$infor = json_decode($sure);
$twitShar= $infor->count;
This works perfectly. Using the link in a browser tells me:
{"count":0,"url":"http:\/\/www.1millionmilesforellie.co.uk\/"} and I am able to access the 0 value with the code above.
For instagram I am trying to do the same (I have my access token and the link works in the browser but I have just hidden it below) but I can't seem to get the value of media_count with this code:
$ch = curl_init("https://api.instagram.com/v1/tags/1mmilesforellie?access_token=MYACCESSTOKEN");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$hash = curl_exec($ch);
curl_close($ch);
$tags = json_decode($hash);
$insta= $tags->media_count;
When I input the link into the browser it gives me the following:
{"meta":{"code":200},"data":{"media_count":1,"name":"1mmilesforellie"}}
I am just trying to get the value of media_count into the variable $insta but it doesn't seem to be working. Is it because there are braces around "data" value? Do I need to do something differently than in the Twitter example?
Thanks for your help!