Last active
December 20, 2021 09:22
-
-
Save Momijinn/b6bb43a92fac50ff3c49078888d8257e to your computer and use it in GitHub Desktop.
sample request instagram api
This file contains hidden or 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
#!/usr/bin/env python3.8 | |
# -*- coding: utf-8 -*- | |
import requests | |
token = '${USER_TOKEN}' | |
host = 'https://graph.facebook.com/v12.0' | |
# get user_page_id | |
user_page_url_query = { | |
'access_token': token | |
} | |
user_page_url = '{}/me/accounts'.format(host) | |
r = requests.get(user_page_url, params=user_page_url_query) | |
res = r.json() | |
user_page_id = res['data'][0]['id'] | |
print(user_page_id) | |
# get user_id | |
user_id_url_query = { | |
'fields': 'instagram_business_account', | |
'access_token': token, | |
} | |
user_id_url ='{}/{}'.format(host, user_page_id) | |
r = requests.get(user_id_url, params=user_id_url_query) | |
res = r.json() | |
user_id = res['instagram_business_account']['id'] | |
print(user_id) | |
# get hash tag id | |
hash_tag_id_query = { | |
'user_id': user_id, | |
'q': 'カメラ', | |
'access_token': token, | |
} | |
hash_tag_id_url = '{}/ig_hashtag_search'.format(host) | |
r = requests.get(hash_tag_id_url, params=hash_tag_id_query) | |
res = r.json() | |
hash_tag_id = res['data'][0]['id'] | |
print(hash_tag_id) | |
# get hash tag search | |
hash_tag_search_query = { | |
'user_id': user_id, | |
'fields': 'caption', | |
'access_token': token, | |
'limit': 5, | |
} | |
edge = 'top_media' | |
hash_tag_search_url = '{}/{}/{}'.format(host, hash_tag_id, edge) | |
r = requests.get(hash_tag_search_url, params=hash_tag_search_query) | |
res = r.json() | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment