Jump to content

Using curl for social media counts


Sitesfo2
Go to solution Solved by fastsol,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.