0
I’m trying to get comments from instagram posts.
With the code below, I can catch a json with some information about the post through the post link with a parameter __a=1: https://instagram.com/p/post-code/? __a=1
The post-code is the post code, for example: Candglqjl2j
Ignore the space in the "links" instagram, because I can not post more than 8 links here.
import json, requests
url = 'https:// instagram . com/p/CAnDglQJl2J/?__a=1'
response = requests.get(url)
data = json.loads(response.text)
print(data)
The answer returned by the above code is a json with some posting information, including some (not all) comments, and some other information indicating whether that post has more records (in this case, comments).
To continue picking up the rest of the comments, I need to request the following query url: https://instagram . com/graphql/query/? query_hash=hash-code&variables={"shortcode": post-code, "first": 12, "after": end_cursor}
The value of hash code is a hash indicating the operation to be performed (in this case, get more comments), and the value of it at this time is: bc3296d1ce80a24b1b6e40b1e72903f5
The key shortcode is the posting code (Candglqjl2j).
The key first is the amount of records (comments) that will be returned.
The value of the key after in the url query is exactly what I need to get more comments, and the value of the same I find in the key end_cursor contained in the json response of the first request (https://instagram . com/p/Candglqjl2j/? __a=1).
The problem is that when I request from the browser, by placing the request link (https://instagram . with/p/Candglqjl2j/?__a=1) in the request’s url field, json is shown normally, and the key value end_cursor is presented as follows::
"{\"cached_comments_cursor ": "18112231093126073 ", "bifilter_token ": "Kiobarya0abwaegaoaaoabgaeaaqaagacaaiaf07zzz5na88vaxs35x9_1ek5934vfrnhr99gslxaafmdmw3zdzufvnwzyekbrzmrr4lfafloz2n4jwvtl4fj_iuoffl__pf_t_uotf-X96u95jx6vd__yq_vunx9_qu-Jgtlsjniwhfarqyiwcaaaaa==\"}"
But when I request for python, it returns the json with the key value end_cursor presented as follows:
QVFETVdxME5fLXJ3TGEzVE5yaXNiby1ydnpUVkFJaEFsZGxYVkJDNVJ3d0IzNlBPV2p0R1R3OGI5eHZXdzhnUGhYWk8yall2R2tYZzdlYVdkbm00T2VoNg==
Because the value of the same key is presented one way in the browser, and another completely different in python?
I need to know how to get the key value end_cursor in python in the same way it is displayed in the browser, for the request in query url to work (https://instagram . com/graphql/query/?query_hash=hash-code&variables={"shortcode": post-code, "first": 12, "after": end_cursor})because I tried with the format that python returns to me but it doesn’t work.
For example, to get more comments, I need to make a request as follows in python:
import json, requests
url = 'https:// instagram . com/graphql/query/?query_hash=bc3296d1ce80a24b1b6e40b1e72903f5&variables={"shortcode": "CAnDglQJl2J", "first": 12, "after": "{\"cached_comments_cursor\": \"17856088486976357\", \"bifilter_token\": \"KEQBDACgABgAEAAQAAgACAD_3_f__P_vf_v_9f7____7u-_36zfoHB8tutf7__9_f33_tf____ff_57_6--__qf4HtTIgAA=\"}"}'
response = requests.get(url)
data = json.loads(response.text)
print(data)
Remembering that the value of end_cursor i got the json returned by the first request (https://instagram . com/p/Candglqjl2j/? __a=1)
Because the value of the key end_cursor of the same request is presented one way in the browser and another way in python? And how can I solve this problem?
Because the request using the url query does not return me comments in json when I use the key value end_cursor python-printed.
For example:
import json, requests
url = 'https:// instagram . com/graphql/query/?query_hash=bc3296d1ce80a24b1b6e40b1e72903f5&variables={"shortcode": "CAnDglQJl2J", "first": 12, "after": "QVFETVdxME5fLXJ3TGEzVE5yaXNiby1ydnpUVkFJaEFsZGxYVkJDNVJ3d0IzNlBPV2p0R1R3OGI5eHZXdzhnUGhYWk8yall2R2tYZzdlYVdkbm00T2VoNg=="}'
response = requests.get(url)
data = json.loads(response.text)
print(data)
This is returned here, both in the browser and in python:
That’s why I need python to return the value of this key in the same format as it is displayed in the browser, as shown in the images, because only then does a json containing more comments get returned (and other information too).
For example:
import json, requests
url = 'https:// instagram . com/graphql/query/?query_hash=bc3296d1ce80a24b1b6e40b1e72903f5&variables={"shortcode": "CAnDglQJl2J", "first": 12, "after": "{\"cached_comments_cursor\": \"17856088486976357\", \"bifilter_token\": \"KEQBDACgABgAEAAQAAgACAD_3_f__P_vf_v_9f7____7u-_36zfoHB8tutf7__9_f33_tf____ff_57_6--__qf4HtTIgAA=\"}"}'
response = requests.get(url)
data = json.loads(response.text)
print(data)
This is returned here in the browser, because in python the key value end_cursor is that other way:
PS: The post-code and end_cursor values shown here are illustrative.
I really appreciate anyone who can help me.
Hello. I accessed through the anonymous tab and really, the value of the key end_cursor has the same format that is presented by python. Could you tell me what kind of encryption that is?
– Gabriel Otto
I have to be logged in to receive the json with the end_cursor key value the way I need it, I just tested it here. There’s a way I can authenticate on instagram with python, just so I can solve the problem?
– Gabriel Otto