pgrimaud/instagram-user-feed

403 Forbidden

mdagostino opened this issue · 17 comments

With the new update ( 3.0 ) this error still not fixed. Maybe needs more parameters in to the cookie.

With this cURL works perfectly

curl 'https://www.instagram.com/graphql/query/?query_hash=42323d64886122307be10013ad2dcc44&variables=%7B%22id%22%3A%22249799003%22%2C%22first%22%3A12%2C%22after%22%3A%22AQBuO8IqsUxx0MdR7HgMAViNQUZdSXqPDCul6ryZ0gOIOKJQAXFQf4D2uyNUTgqnybnYyCS-xEzuSeNf6r3useVYFTmXpGqRpCxTjvdYHIiaiw%22%7D' -H 'cookie: rur=ATN; csrftoken=xru6MzvqtGWPPwIgFZTOMhofzkrc363l; mid=Ws4PtAAEAAHYZpIjJVyqOJ1mAzgb; ig_vw=1680; ig_pr=1; ig_vh=156; urlgen="{"time": 1523453876}:1f6Fwl:eVeElpFOqAFuG6XmZrlYCyycGyM"' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9,es;q=0.8' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36' -H 'accept: /' -H 'referer: https://www.instagram.com/caindependiente/' -H 'authority: www.instagram.com' -H 'x-requested-with: XMLHttpRequest' -H 'x-instagram-gis: 54ad531e876d39620e9ba295f076decc' --compressed

But I cannot reproduce it in code.

I'll tried

    $cookieJar = CookieJar::fromArray([
        'ig_pr' => '1'
        ,'rur'  => 'ATN'
        ,'csrftoken'  => 'xru6MzvqtGWPPwIgFZTOMhofzkrc363l'
        ,'mid'  => 'Ws4PtAAEAAHYZpIjJVyqOJ1mAzgb'
        ,'ig_vw'  => '1680'
        ,'ig_vh'  => '156'
        ,'urlgen'  => '{"time": 1523453876}:1f6Fwl:eVeElpFOqAFuG6XmZrlYCyycGyM"'
    ], 'instagram.com');

Have the same error. You are using GraphQL which is not the endpoint this package uses which is https://www.instagram.com/username?__a=1

Forbidden 403 :-(

It seems like we are not alone in this:
postaddictme/instagram-php-scraper#336

And the fix with hardcoding in a cookie does seem a bit fragile. Hm...
postaddictme/instagram-php-scraper#335

I'm gonna try to generate a cookie with login / password.

Something like this :

$api = new Api();

// for media, userId is mandatory!
$api->setUserId(184263228);
$api->setLogin('pgrimaud');
$api->setPassword('password123');

$api->retrieveMediaData(true);

$feed = $api->getFeed();

What do you think about it? @jannejava @mdagostino

@mdagostino holy shit... until when?

Could be hard to get it to work over time. If the cookie could work to 2020 I would be happy. ;-)

https://developers.facebook.com/blog/post/2018/01/30/instagram-graph-api-updates/

The following will be available until early 2020:

Basic - to read a user’s profile info and media

@mdagostino how did you create the link and the query_hash?

@jannejava This link refers to the official Instagram API.

The query_hash is hardcoded from the Instagram website. (You can see it here https://github.com/pgrimaud/instagram-user-feed/blob/master/src/Instagram/Transport/JsonFeed.php#L11)

The link is broken again, may be we need to find another work around.

I wonder if we can use the same logic that http://instafeedjs.com/ does. It uses an access token. e.g. it creates a url like https://api.instagram.com/v1/users/5467372861/media/recent?access_token=5467372861.1677ed0.8bd9ec9b2d4d48a8b36dc891edcadcf3 - that url works for me with curl on cli ? It does mean you have to authenticate to get a token but is once-only

More info I get the user id from https://smashballoon.com/instagram-feed/find-instagram-user-id/ and get an access token by going to http://instagram.pixelunion.net/ - it only gives you access to your user account though.
Edit not sure how to find your own instagram user id, they've changed the api :(

Edit again. I found my instagram id by looking at the page source of https://www.instagram.com/jmarshall.com.au/ - at the start of the inline script tag is some data, e.g. for me "id":"6753818688"
So using the access token from pixelunion.net and my instagram id I can make up the url https://api.instagram.com/v1/users/6753818688/media/recent?access_token=6753818688.1677ed0.3896890c31a0452782a259a0b24e5322 and that returns json of my instagram posts. Does this help at all, or is this project more for finding other people's feeds?

I have created a fork and a pull request and I got it working for me now again.

  • You need to create an access token from http://instagram.pixelunion.net/
  • The first part of the access token before the first . seems to be your user ID
  • Seems like you can only access your own media until 2020 other user's media December 11, 2018

I have just tried it to display my own media so I may have broken some other functionality.

https://github.com/jannejava/instagram-user-feed

Many thanks @jannejava

I fixed all tests and the release 4.0.0 is now working.

Seems like you can only access your own media until 2020 other user's media December 11, 2018

We must find any solution to use the new Instagram API (graphQL) before end of the year.

Instagram's Graph API requires:

  • A Facebook Page
  • An Instagram Business Account
  • Facebook Login (OAuth)
  • An app submission to Facebook showing how the Instagram API will be used
  • Approval for said app

I haven't looked in to the T&C but programmatic access for displaying content on another website is probably not going to lead to approval, and all of that seems to be out of scope for this package anyways.

@cookieguru Yeah, It's a pain in the ass.
I will probably simulate a login process with login and password. Then fetch data with cookie generated with credentials.

I have the same problem when I try to get followers

@prince-code Which version do you use?

If you use Java Spring Back-end and Jsoup for web scrolling, there is a workaround. Referrence following.

screenshot 2019-01-22 at 18 24 32