pgrimaud / instagram-user-feed

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.
MIT License
873 stars 136 forks source link

403 Forbidden #5

Closed mdagostino closed 6 years ago

mdagostino commented 6 years ago

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

mdagostino commented 6 years ago

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');
jannejava commented 6 years ago

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 :-(

jannejava commented 6 years ago

It seems like we are not alone in this: https://github.com/postaddictme/instagram-php-scraper/issues/336

And the fix with hardcoding in a cookie does seem a bit fragile. Hm... https://github.com/postaddictme/instagram-php-scraper/pull/335

pgrimaud commented 6 years ago

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 commented 6 years ago

Now this link works

https://www.instagram.com/graphql/query/?query_hash=472f257a40c653c64c666ce877d59d2b&variables={"id":"1368353436","first":12}

pgrimaud commented 6 years ago

@mdagostino holy shit... until when?

jannejava commented 6 years ago

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?

pgrimaud commented 6 years ago

@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)

mdagostino commented 6 years ago

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

joshbmarshall commented 6 years ago

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?

jannejava commented 6 years ago

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

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

pgrimaud commented 6 years ago

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.

cookieguru commented 6 years ago

Instagram's Graph API requires:

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.

pgrimaud commented 6 years ago

@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.

peyman-se commented 6 years ago

I have the same problem when I try to get followers

pgrimaud commented 6 years ago

@prince-code Which version do you use?

limjinsun commented 5 years ago

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