postaddictme / instagram-java-scraper

Instagram Java Scraper. Get account information, photos, videos and comments.
449 stars 150 forks source link

getCommentsByMediaCode/getMediaLikes not working #112

Open dankarization opened 6 years ago

dankarization commented 6 years ago

Since yesterday these two methods doesn't work. You get 403 with INFO: {"message": "forbidden", "status": "fail"}, even if you try to connect to graphql link through browser, but without cookie.

carvalholuan commented 6 years ago

Same problem here.

igor-suhorukov commented 6 years ago

Instagram API issues related to: https://github.com/postaddictme/instagram-php-scraper/issues/325 https://github.com/postaddictme/instagram-php-scraper/issues/326

tolgaduzenli commented 6 years ago

do we have anything to do ?

myrs commented 6 years ago

@tolgaduzenli, this may be a way to solve it: in that comment I described the solution in python, I think this could be taken as a base to implemented the java solution. In brief:

  1. New API url should be used: https://www.instagram.com/graphql/query/?query_hash=42323d64886122307be10013ad2dcc44&variables={"id":"<user_id>","first":<items_to_retrieve>,"after":"<end_cursor>"}
  2. Now it's obligatory to send cookies with request, so first need to get them somehow (my solution is to load instagram.com page with automated browser, maybe there is a better solution)
myrs commented 6 years ago

As mentioned in php scrapper, cookies I retrieved one day ago still work. So maybe the automated browser part to retrieve them might be omitted for now to make media queries work again until final solution is found. It'd be just update URL to new one and send the same cookies always.

myrs commented 6 years ago

@dankarization hi! @rhcarlosweb found a solution for this in https://github.com/postaddictme/instagram-php-scraper/issues/325 with just sending one cookie ig_pr for this request! https://github.com/postaddictme/instagram-php-scraper/pull/328/files Hope this helps 😄

dankarization commented 6 years ago

Tried to set ig_pr cookie- doesn't work for me :c We have this solution in php scrapper We have this solution in

Send the following cookies with request. I just checked - the cookies I retrieved yesterday still work (one day now) and from different clients, without need to get the new ones before each request. So automated browser part might be omitted for now:

[
    {
        "domain": "www.instagram.com",
        "httpOnly": false,
        "name": "rur",
        "path": "/",
        "secure": false,
        "value": "PRN"
    },
    {
        "domain": "www.instagram.com",
        "httpOnly": false,
        "name": "ig_vw",
        "path": "/",
        "secure": false,
        "value": "1038"
    },
    {
        "domain": "www.instagram.com",
        "expiry": 1554672942.248612,
        "httpOnly": false,
        "name": "csrftoken",
        "path": "/",
        "secure": true,
        "value": "ObRXje2ByOUmAnxqPaoFsD0CHvBEK8dQ"
    },
    {
        "domain": "www.instagram.com",
        "expiry": 2153943342.248646,
        "httpOnly": false,
        "name": "mid",
        "path": "/",
        "secure": false,
        "value": "WsqLMgALAAFkkaMz9rbL568BCU5N"
    },
    {
        "domain": "www.instagram.com",
        "httpOnly": false,
        "name": "ig_vh",
        "path": "/",
        "secure": false,
        "value": "532"
    },
    {
        "domain": "www.instagram.com",
        "httpOnly": false,
        "name": "ig_pr",
        "path": "/",
        "secure": false,
        "value": "2.5"
    }
]

But i don't understand how to set this as cookie using java, found nothing. Could someone help pls?

engnaguib commented 6 years ago

any update?

dankarization commented 6 years ago

Using HTTPURLCONNECTION request.setRequestProperty("Cookie","rur=PRN&ig_vw=1038&csrftoken=ObRXje2ByOUmAnxqPaoFsD0CHvBEK8dQ&mid=WsqLMgALAAFkkaMz9rbL568BCU5N&ig_vh=532&ig_pr=2.5"); This bullshit will save your life

Saiirex commented 6 years ago

Is there a way to do it with javascript?

farseev commented 6 years ago

@igor-suhorukov, sorry for bothering. Just for our information, do you know if the library planned to be fixed any time soon?

Thanks for your help with this brilliant lib!

igor-suhorukov commented 6 years ago

@farseev I know but I haven't time for that. Any pull request with fixes are welcome!

rodrigae commented 6 years ago

I haven't used your API in a while, I actually used your login methods and build the rest for what I was working on. I just looked at your EndPoints, half of those links don't work or have has been locked. Most of the request now required for the user to be logged in. All request are down to 200 in a hour from 5,000 in a hour.(Lame), I'll share below the requests that I am using, and hopefully you guys understand the naming. keep in mind the JSON that comes back has changed for a few also.

//this link will only provide user profile image and ID private static String userProfilePic = "https://www.instagram.com/graphql/query/?query_hash=bfe6fc64e0775b47b311fc0398df88a9&variables=%7B%22user_id%22%3A%22{AccountId}%22%2C%22include_chaining%22%3Afalse%2C%22include_reel%22%3Atrue%2C%22include_suggested_users%22%3Afalse%2C%22include_logged_out_extras%22%3Afalse%7D"; //Link below will be used to get followers, and following on a user information private static String userFollowers = "https://www.instagram.com/graphql/query/?query_hash=37479f2b8209594dde7facb0d904896a&variables=%7B%22id%22%3A%22{AccountId}%22%2C%22first%22%3A{followerCount}%7D"; private static String userFollowings = "https://www.instagram.com/graphql/query/?query_hash=58712303d941c6855d4e888c5f0cd22f&variables=%7B%22id%22%3A%22{AccountId}%22%2C%22first%22%3A{followingCount}%7D"; //Link below can get user media list and also the media count private static String userMedia = "https://www.instagram.com/graphql/query/?query_hash=42323d64886122307be10013ad2dcc44&variables=%7B%22id%22%3A%22{AccountId}%22%2C%22first%22%3A{mediaCount}%7D"; //Link to obtain user information from tags private static String Tag = "https://www.instagram.com/graphql/query/?query_hash=ded47faa9a1aaded10161a2ff32abb6b&variables=%7B%22tag_name%22%3A%22{TagName}%22%2C%22first%22%3A{TotalUsers}%7D"; //Link to get user information for locations private static String Location = "https://www.instagram.com/graphql/query/?query_hash=ac38b90f0f3981c42092016a37c59bf7&variables=%7B%22id%22%3A%22{locationID}%22%2C%22first%22%3A{TotalUsers}%7D"; //Get the user account Activity private static String AccountActivity = "https://www.instagram.com/accounts/activity/?__a=1"; //get information on a image private static String ShortCodeInformation = "https://www.instagram.com/p/{ShortCode}/?__a=1"; //this is to search for a user and their information private static String UserSearch = "https://www.instagram.com/web/search/topsearch/?context=blended&query={username}"; //Comment on media private static String Comment = "https://www.instagram.com/web/comments/{MediaID}/add/"; //Follow userid private static String Follow = "https://www.instagram.com/web/friendships/{UserID}/follow/"; //Like Media By Code private static String Like = "https://www.instagram.com/web/likes/{mediaID}/like/"; //Unfollow user private static String UnFollow = "https://www.instagram.com/web/friendships/{UserID}/unfollow/";

CodeCombiner commented 4 years ago

Using HTTPURLCONNECTION request.setRequestProperty("Cookie","rur=PRN&ig_vw=1038&csrftoken=ObRXje2ByOUmAnxqPaoFsD0CHvBEK8dQ&mid=WsqLMgALAAFkkaMz9rbL568BCU5N&ig_vh=532&ig_pr=2.5"); This bullshit will save your life

@dankarization the method does not work again and this solution does not work anymore because the time has passed. I wonder have you any other suggestions how to fix it this time?