Bolandish / PHP-Instagram-Grabber

A workaround for the new Instagram policy to get images by hashtag and user id. No need for accesstoken :)
151 stars 39 forks source link

Instagram changed #40

Open ncmsalzburg opened 7 years ago

ncmsalzburg commented 7 years ago

Hi, it seems like that Instagram has been changed again. The /query/ endpoint does not work since today.

sabilawijaya commented 7 years ago

yes, same problem here since today

maddo7 commented 7 years ago

Does somebody know if the Endpoint is completely gone or still works with login? Where was the query Endpoint used on the website? When I look through the website, https://www.instagram.com/graphql/query/ is used. Maybe they replaced them?

ethereali commented 7 years ago

seems like old method working again without authorization u can get json data from https://www.instagram.com/username/?__a=1 or https://www.instagram.com/explore/tag/?__a=1 and paginate via end_cursor

$baseUrl = 'https://www.instagram.com/explore/tags/tag/?__a=1';
$url = $baseUrl;

while(1) {
    $json = json_decode(file_get_contents($url));
    print_r($json->tag->media->nodes);
    if(!$json->tag->media->page_info->has_next_page) break;
    $url = $baseUrl.'&max_id='.$json->tag->media->page_info->end_cursor;
}
maddo7 commented 7 years ago

Yes, but the query parameter is much more flexible than that.

slackday commented 7 years ago

Anyone figured out what's going on? I can't see any documented changes on https://www.instagram.com/developer/changelog/

And I can't figure out end-points in previous comments :|

paha77 commented 7 years ago

They don't need to document it as it's not an official API endpoint or something...

slackday commented 7 years ago

Ok sorry, I have a hard time following what's happening and why it's not working anymore. Any suggestion on how to fix it?

SEMNON commented 7 years ago

Would be great to know if a fix is in the works?

shelontwo commented 7 years ago

Hello, have a solution?

Bolandish commented 7 years ago

If any got a solution for this, please make a PR :)

mbilgidhis commented 7 years ago

What @ethereali wrote actually gives temporary solution. It's not the same as query parameter result, but it gives essential data for fetching hashtag. It lacks of owner details. But you can get them from https://www.instagram.com/p/blabla/?__a=1

shelontwo commented 7 years ago

Awesome 🗡

header('Content-Type: application/json');
    $baseUrl = 'https://www.instagram.com/explore/tags/crossfitconcordia/?__a=1';
    $url = $baseUrl;
    $json = json_decode(file_get_contents($url));
    $jsonImagens = "[";
    $total = count($json->tag->media->nodes);
    $soma = 0;
    foreach ($json->tag->media->nodes as $key => $value) {
        $soma++;
        $jsonImagens .= '{"display_src":"'.$value->display_src.'","code": "'.$value->code.'"}';
        if($soma != $total){
           $jsonImagens .= ",";  
        }
    }  
    $jsonImagens .= "]";   
    print_r(($jsonImagens));
scottyzen commented 7 years ago

Is there any update. Has anyone been able to find a solution?

max-kk commented 7 years ago

HI everyone,

Now possilbe request with using https://www.instagram.com/graphql/query/ endpoint

Because https://www.instagram.com/explore/tag/?__a=1 for me does not work with "end_cursor"

Example: https://www.instagram.com/graphql/query/?query_id=17882293912014529&tag_name=best_photo&first=9&after=J0HWVISlQAAAF0HWVCuAwAAAFjwA

The question is how query_id is generated. Current value "17882293912014529" work at least 10 days. But it can be changed at any moment for another value.

first - count after - end_cursor

Just returned data have some chnaged fields names, os I used "normalize" function:

    public static function _normalizeEdgeEntries($nodes)
    {
        $normalized = array();
        foreach ($nodes as $node) {
            $normalized[] = (object)array(
                "id" => $node->node->id,

                "owner" => $node->node->owner,
                "code" => $node->node->shortcode,
                "date" => $node->node->taken_at_timestamp,

                "is_video" => $node->node->is_video,
                "thumbnail_src" => $node->node->thumbnail_src,
                "display_src" => $node->node->display_url,
                "dimensions" => $node->node->dimensions,

                "comments" => $node->node->edge_media_to_comment,
                "likes" => $node->node->edge_liked_by,
                "caption" => isset($node->node->edge_media_to_caption->edges[0]->node->text) ? $node->node->edge_media_to_caption->edges[0]->node->text : '',

            );
        }
//        "comments_disabled": false,
//                      "id": "1545479499906608694",
//                      "edge_media_to_caption": {
//            "edges": [{
//                "node": {
//                    "text": "\ud83d\udd32\nIndigo Slam; Central Park; Sydney; Australia\nby William Smart Design Studio\n.\n.\n.\n#architecture #architect #architecture_lover #archilover #day_photo #best_photo #art #arch #design #designer #modernism #modern_architecture #archido #idea #live #better_world #better_life #luxury #construct #volume #building #build #old #old_modernism #black\u0026white #B\u0026W"
//                              }
//                          }]
//                      },
//                      "shortcode": "BVypWq3lO42",
//                      "edge_media_to_comment": {
//            "count": 0
//                      },
//                      "taken_at_timestamp": 1498455534,
//                      "dimensions": {
//            "height": 640,
//                          "width": 640
//                      },
//                      "display_url": "https://scontent-ams3-1.cdninstagram.com/t51.2885-15/e35/19425294_108746296416893_3924234936009097216_n.jpg",
//                      "edge_liked_by": {
//            "count": 109
//                      },
//                      "owner": {
//            "id": "3193971795"
//                      },
//                      "thumbnail_src": "https://scontent-ams3-1.cdninstagram.com/t51.2885-15/e35/19425294_108746296416893_3924234936009097216_n.jpg",
//                      "is_video": false
        return $normalized;
    }
RD1612 commented 7 years ago

The fix from @shelontwo works great for me

rickymatthews commented 7 years ago

The advantage of the plugin before, was the fact it could iterate through pages. The workaround in the thread only fetches the first page?

freddurst1805 commented 6 years ago

Someone does know how to get username from id ?

alyysaafan commented 6 years ago

when i run this link "https://www.instagram.com/?__a=1" it returns {"graphql":null} anyone knows why this happens?

rickymatthews commented 6 years ago

@alyysaafan should be like https://www.instagram.com/explore/tags/330ci/?__a=1

alyysaafan commented 6 years ago

@rickymatthews use it when it is like that "https://www.instagram.com/?__a=1" it should returns recent feed, i used it on many accounts worked fine but when i use it on my account it returns {"graphql":null}

rickymatthews commented 6 years ago

is your account private? @alyysaafan

alyysaafan commented 6 years ago

@rickymatthews no

verybigelephants commented 6 years ago

well, then use https://www.instagram.com/_your_account_/?__a=1 no?