Last active
August 11, 2017 12:33
-
-
Save farbod-s/6033dda9157b2da9925fa2b68655eee9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding=utf8 | |
import sys | |
import requests | |
import json | |
query = 'https://www.instagram.com/graphql/query' | |
id_query_followers = '17851374694183129' | |
id_query_followings = '17874545323001329' | |
headers = { | |
'Origin': 'https://www.instagram.com', | |
'Referer': 'https://www.instagram.com/golfarahani/', | |
'x-csrftoken': '{{CSRF_TOKEN}}', | |
'x-instagram-ajax': '1', | |
'Cookie': '{{YOUR_COOKIE}}', | |
'User-Agent': '{{USER_AGENT}}' | |
} | |
headers2 = { | |
'Origin': 'https://www.instagram.com', | |
'Referer': 'https://www.instagram.com/', | |
'x-csrftoken': '{{CSRF_TOKEN}}', | |
'Cookie': '{{YOUR_COOKIE}}', | |
'User-Agent': '{{USER_AGENT}}' | |
} | |
variables = { | |
'id': '1705191588', #golfarahani | |
'first': '20', | |
'after': '{{END_CURSOR}}' | |
} | |
params = { | |
'query_id': id_query_followers, | |
'variables': json.dumps(variables) | |
} | |
session = requests.session() | |
# get followers of @golfarahani | |
response = session.get(query, params=params, headers=headers2) | |
response = response.json() | |
print response['data']['user']['edge_followed_by']['edges'][0]['node']['username'] | |
# follow @golfarahani | |
query_follow = 'https://www.instagram.com/web/friendships/1705191588/follow/' | |
response = session.post(query_follow, headers=headers) | |
response = response.json() | |
print json.dumps(response) | |
#unfollow @golfarahani | |
query_unfollow = 'https://www.instagram.com/web/friendships/1705191588/unfollow/' | |
response = session.post(query_unfollow, headers=headers) | |
response = response.json() | |
print json.dumps(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment