Open cbenjamin opened 6 years ago
@cbenjamin same problem. I think Instagram are after changing something on their side again. Anyone have a way around?
Hi guys,
I see that https://www.instagram.com/explore/tags/best_photos/?__a=1 is working, so nonthig changed in Instagram API.
My current code:
/**
* @param null $hashtag
*
* @return array|bool
* @since 1.01 (CORE)
*/
public static function getSimpleMediaByHashtag($hashtag = null)
{
// https://www.instagram.com/graphql/query/?query_id=17882293912014529&tag_name=best_photo&first=9&after=J0HWVISlQAAAF0HWVCuAwAAAFjwA
if (empty($hashtag) || !is_string($hashtag)) {
return false;
}
$random = self::generateRandomString();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf("https://www.instagram.com/explore/tags/%s/?__a=1", $hashtag));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = array();
$headers[] = "Cookie: csrftoken=$random;";
$headers[] = "X-Csrftoken: $random";
$headers[] = "Referer: https://www.instagram.com/";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
//die();
//var_dump($response);
if ($response) {
$media = json_decode($response, false);
} else {
return false;
}
if (!isset($media->tag->media->nodes)) {
fv_log("Instagram :: Simple request nodes is empty!", $media);
return false;
}
return array('all_media' => (array)$media->tag->media->nodes, 'page_info' => (object)array('has_next_page' => false, 'end_cursor' => '',));
}
Thank you @max-kk. I got it working again.
great thank you @max-kk ! On Laravel The function fv_log is not declared , it works with die and debug function but not fv_log ?
`public static function getSimpleMediaByHashtag($hashtag = null) { if (empty($hashtag) || !is_string($hashtag)) { return false; }
$random = self::generateRandomString();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf("https://www.instagram.com/explore/tags/%s/?__a=1", $hashtag));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = array();
$headers[] = "Cookie: csrftoken=$random;";
$headers[] = "X-Csrftoken: $random";
$headers[] = "Referer: https://www.instagram.com/";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
//die();
//var_dump($response);
if ($response) {
$media = json_decode($response, true);
} else {
return false;
}
return $media['graphql']['hashtag']['edge_hashtag_to_media']['edges'];
}`
work for me
Using the same example from the docs
Bolandish\Instagram::getMediaByHashtag("nofilter", 10);
Response is always null. Every other function works well except for getMediaByHashtag. Am I missing something?