Skip to content

Instantly share code, notes, and snippets.

@Guley
Created May 10, 2019 05:27
Show Gist options
  • Save Guley/ad645318fff7420840c7418046932d3c to your computer and use it in GitHub Desktop.
Save Guley/ad645318fff7420840c7418046932d3c to your computer and use it in GitHub Desktop.
Get instagram data using php and curl
protected function instagram(){
$access_token = 'xxxxxx';
$fullendpoint = 'https://api.instagram.com/v1/users/self/media/recent/';
$endpoint = 'users/self/media/recent/';
$params = array(
'access_token' => $access_token,
'count' => '10',
'min_tag_id' => '',
'max_tag_id' => ''
);
$secret = 'xxxxxxxxx';
$sig = $this->generate_sig($endpoint, $params, $secret);
$return = $this->getInsta($fullendpoint."?access_token=".$access_token.'&sig='.$sig);
$instagramPost = json_decode($return);
return $instagramPost;
}
protected function generate_sig($endpoint, $params, $secret) {
$sig = $endpoint;
ksort($params);
foreach ($params as $key => $val) {
$sig .= "|$key=$val";
}
return hash_hmac('sha256', $sig, $secret, false);
}
protected function getInsta($api_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,$api_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment