Is possible to retrieve queryhash string for an Instagram post?
#10
Closed
opened 2 years ago by youngvo
·
16 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Hi Kali,
Thanks for writing this library.
Currently, the library is able to retrieve the queryhash string for getting hashtag's post. I'm concerned that it is possible to apply the same mechanims to retrieve the queryhash string for getting the information of a post. Please advise.
Best,
-Young
Is possible to retrieve queryhash for a Instagram post?to Is possible to retrieve queryhash string for an Instagram post? 2 years agoHello Young,
In which case do you need a query hash for a post ?
As far as I know, you only need a shortcode for a post.
The shortcode is provided in all methods that returns an array of posts.
Hi Kali,
Actually, I would like to get the post without authentification by fetching the queryhash call, like this https://www.instagram.com/graphql/query/?query_hash=cf28bf5eb45d62d4dc8e77cdb99d750d&variables={"shortcode":"CNBg--UguoF","child_comment_count":3,"fetch_comment_count":40,"parent_comment_count":24,"has_threaded_comments":true}
Any ways to archive this?
Best,
-Young
You already can get this post without authentication using the following code :
Which returns :
Thanks for your kind reply. I tried the code snippet you suggested above. It always say: 404. No response returned.
Since there is no hard-coded 404 response, this code must be coming from Instagram directly.
But, I am able to see this post myself, which is weird.
The only case I'd guess where one of two people gets a 200 response while the other gets a 404 response is when the latter has no access to the resource and the server uses secrecy instead of denial.
But, since none of us are using authentication, this situation should be impossible.
Can you try from another IP address ?
Today I tried again. It threw the error code 429. Is it from this code snippest?
Yes : when hitting rate limits, Instagram doesn't explicitly return an HTTP
429 Too Many Requests
response, but a302 Found
(temporary redirect) pointing to the login page.Since there are different rate limits for anonymous and authenticated requests, you could be able to immediately bypass this rate limitation by authenticating now.
However, you may hit another rate limit later.
Thanks Kaki for your response.
Actually, I'm seeing in your library code, it invokes the endpoint
https://www.instagram.com/p/CNBbcLJgqXG/__a=1
to retrieve the metadata of a post. However this endpoint requires an authentification. Hence, Instagram redirects you to the login page.Without the authentification, you can make a call to this endpoint
https://www.instagram.com/graphql/query/?query_hash=cf28bf5eb45d62d4dc8e77cdb99d750d&variables={"shortcode":"CNBbcLJgqXG"}
to retrieve the metadata of the post. Can you add this endpoint to your library?No, the endpoint is only called when you're authenticated, see :
When not authenticated, the full browser page will be scraped, see :
I see the endpoint works indeed, but in order to scrape the query hash of any client, can you please tell me on which page, doing which action, did you triggered this GraphQL query ?
Thanks.
Looks like this one is not working as expected. It always return 429 instead of scraping the web page.
When you view posts under a hashtag, for example: https://www.instagram.com/explore/tags/miamiboatlife/. You click on one post to see the detail. Then, you navigate to the next post. Open the web inspector, you will see it calls the endpoint
https://www.instagram.com/graphql/query/?query_hash=cf28bf5eb45d62d4dc8e77cdb99d750d&variables={"shortcode":"CNBbcLJgqXG"}
Do you mean 429 ?
Because 409 is something else.
The library returns 429 when the client is redirected to the login page.
The library returns 409 when the client is redirected to the captcha page.
The latter would only happen when you're authenticated.
I'll try that, thanks.
yes, I meant 429. Thanks for your attention to add the new endpoint.
I just added a parameter to the
getPost
method so you can use a query hash on demand. (fc39063
)You should know, though, that GraphQL is also rate-limited by Instagram, just like non-GraphQL requests.
Appricate for your quick reaction on this.
-Young
Do you know exactly the rate limit of Graphql request. Is it 200 request per hour per IP, right? I'm not sure about the mechanims that Insgram is applying. Any info would be helpful.
Unfortunately, I have absolutely no idea which rate limits Instagram is applying on any of its endpoints.