Skip to content

Commit 8eacca7

Browse files
committed
instagram graph api get page/account id with python
1 parent 372e6d7 commit 8eacca7

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# blog_code
1+
# blog_code
2+
3+
This repo contains code from my YouTube/blog tutorials.
4+
5+
YouTube -> https://youtube.com/justinstolpe
6+
Blog: -> https://justinstolpe.com/blog/
7+
8+
==========================================================================
9+
10+
( ( ) ( ) ( (
11+
)\ ) * ) )\ ) ( /( )\ ) * ) ( /( )\ ) )\ )
12+
( ( (()/(` ) /((()/( )\()) (()/(` ) /( )\()) (()/( (()/( (
13+
)\ )\ /(_))( )(_))/(_))((_)\ /(_))( )(_))((_)\ /(_)) /(_)))\
14+
((_) _ ((_)(_)) (_(_())(_)) _((_) (_)) (_(_()) ((_) (_)) (_)) ((_)
15+
_ | || | | |/ __||_ _||_ _| | \| | / __||_ _| / _ \ | | | _ \| __|
16+
| || || |_| |\__ \ | | | | | .` | \__ \ | | | (_) || |__ | _/| _|
17+
\__/ \___/ |___/ |_| |___| |_|\_| |___/ |_| \___/ |____||_| |___|

instagram_graph_api/python/defines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def getCreds() :
1010
creds['graph_version'] = 'v6.0'
1111
creds['endpoint_base'] = creds['graph_domain'] + creds['graph_version'] + '/'
1212
creds['debug'] = 'no'
13+
creds['page_id'] = 'FB-PAGE-ID'
14+
creds['instagram_account_id'] = 'INSTAGRAM-BUSINESS-ACCOUNT-ID'
1315

1416
return creds
1517

109 Bytes
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from defines import getCreds, makeApiCall
2+
3+
def getInstagramAccount( params ) :
4+
""" Get instagram account
5+
6+
API Endpoint:
7+
https://graph.facebook.com/{graph-api-version}/{page-id}?access_token={your-access-token}&fields=instagram_business_account
8+
9+
Returns:
10+
object: data from the endpoint
11+
12+
"""
13+
14+
endpointParams = dict()
15+
endpointParams['access_token'] = params['access_token']
16+
endpointParams['fields'] = 'instagram_business_account'
17+
18+
url = params['endpoint_base'] + params['page_id']
19+
20+
return makeApiCall( url, endpointParams, params['debug'] )
21+
22+
params = getCreds()
23+
params['debug'] = 'no'
24+
response = getInstagramAccount( params )
25+
26+
print "\n---- INSTAGRAM ACCOUNT INFO ----\n"
27+
print "Page Id:"
28+
print response['json_data']['id']
29+
print "\nInstagram Business Account Id:"
30+
print response['json_data']['instagram_business_account']['id']
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from defines import getCreds, makeApiCall
2+
3+
def getUserPages( params ) :
4+
""" Get facebook pages for a user
5+
6+
API Endpoint:
7+
https://graph.facebook.com/{graph-api-version}/me/accounts?access_token={access-token}
8+
9+
Returns:
10+
object: data from the endpoint
11+
12+
"""
13+
14+
endpointParams = dict()
15+
endpointParams['access_token'] = params['access_token']
16+
17+
url = params['endpoint_base'] + 'me/accounts'
18+
19+
return makeApiCall( url, endpointParams, params['debug'] )
20+
21+
params = getCreds()
22+
params['debug'] = 'no'
23+
response = getUserPages( params )
24+
25+
print "\n---- FACEBOOK PAGE INFO ----\n"
26+
print "Page Name:"
27+
print response['json_data']['data'][0]['name']
28+
print "\nPage Category:"
29+
print response['json_data']['data'][0]['category']
30+
print "\nPage Id:"
31+
print response['json_data']['data'][0]['id']

0 commit comments

Comments
 (0)