Jump to content

Using curl for social media counts


Sitesfo2

Recommended Posts

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:

 

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:
 
 
 
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!
Link to comment
https://forums.phpfreaks.com/topic/296931-using-curl-for-social-media-counts/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.