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
import requests | |
import urllib.parse | |
client_id = 777777777777777 # instagram APP ID | |
client_secret = '777777777777777777' # instagarm App Secret | |
redirect_uri = 'https://user_name.github.io/' | |
auth_url = 'https://api.instagram.com/' | |
graph_url = 'https://graph.instagram.com/' | |
def get_the_authorization_window(): | |
url = auth_url + 'oauth/authorize' |
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
def get_short_lived_access_token(code = ''): | |
url = auth_url + 'oauth/access_token' | |
param = dict() | |
param['client_id'] = client_id | |
param['client_secret'] = client_secret | |
param['code'] = code | |
param['grant_type'] = 'authorization_code' | |
param['redirect_uri'] = redirect_uri | |
print("\n param",param) | |
response = requests.post(url=url,data=param) |
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
def get_long_lived_access_token(access_token = ''): | |
url = graph_url + 'access_token' | |
param = dict() | |
param['grant_type'] = 'ig_exchange_token' | |
param['client_secret'] = client_secret | |
param['access_token'] = access_token | |
response = requests.get(url=url,params=param) | |
response = response.json() | |
print("\n long_lived_token_response :-",response) | |
long_lived_access_token = response['access_token'] |
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
def get_refresh_token(access_token = ''): | |
url = graph_url + 'refresh_access_token' | |
param = dict() | |
param['grant_type'] = 'ig_refresh_token' | |
param['access_token'] = access_token | |
response = requests.get(url=url,params= param) | |
response = response.json() | |
access_token = response['access_token'] | |
expires_in = response['expires_in'] | |
return access_token |
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
def get_all_the_media(access_token = ''): | |
url = graph_url + 'me/media' | |
param = dict() | |
param['fields'] = 'id,username,caption,media_type,media_url,permalink,timestamp' | |
param['access_token'] = access_token | |
response = requests.get(url=url,params = param) | |
response = response.json() | |
return response |
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
import requests | |
client_id = 'your_app_id' | |
client_secret = 'your_app_secret' | |
redirect_url = 'your_redirect_url' | |
access_url = 'https://www.facebook.com/v13.0/dialog/oauth?response_type=token&display=popup&client_id=your_client_id&redirect_uri=your_redirect_uri&auth_type=rerequest&scope=user_location%2Cuser_photos%2Cuser_friends%2Cuser_gender%2Cpages_show_list%2Cinstagram_basic%2Cinstagram_manage_comments%2Cinstagram_manage_insights%2Cpages_read_engagement%2Cpublic_profile' | |
graph_url = 'https://graph.facebook.com/v15.0/' | |
def func_get_url(): | |
print('\n access code url',access_url) | |
code = input("\n enter the url") |
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
import requests | |
def func_get_page_id(access_token = ''): | |
url = graph_url + 'me/accounts' | |
param = dict() | |
param['access_token'] = access_token | |
response = requests.get(url = url,params=param) | |
print("\n response", response) | |
response = response.json() | |
print("\n response", response) |
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
def get_user_insights(access_token = '',api_url = '',ig_user_id = '',period = '',metric ='',since = '',until=''): | |
url = api_url + ig_user_id + '/insights' | |
param = dict() | |
param['metric'] = metric | |
param['period'] = period | |
param['since'] = since | |
param['until'] = until | |
param['access_token'] = access_token | |
response = requests.get(url=url,params=param) | |
print("\n response",response) |
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
def get_post_insights(access_token = '',api_url = '',instagram_account_id = ''): | |
url = api_url + instagram_account_id + '/media' | |
param = dict() | |
param['access_token'] = access_token | |
response = requests.get(url=url, params=param) | |
response = response.json() | |
media_insights = [] | |
for i in response['data']: | |
url = api_url + i + '/insights' | |
param = dict() |
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
from flask import Flask,request | |
app = Flask(__name__) | |
@app.route('/messenger_listner',methods=['POST','GET']) | |
def listner(): | |
if request.method == 'POST': | |
print("\n recived_data",request.json) | |
return 'success', 200 | |
elif request.method == 'GET': | |
print("\n received data: ", request.json) |
OlderNewer