File tree Expand file tree Collapse file tree
instagram_graph_api/python Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ \__/ \___/ |___/ |_| |___| |_|\_| |___/ |_| \___/ |____||_| |___|
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 "\n Instagram Business Account Id:"
30+ print response ['json_data' ]['instagram_business_account' ]['id' ]
Original file line number Diff line number Diff line change 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 "\n Page Category:"
29+ print response ['json_data' ]['data' ][0 ]['category' ]
30+ print "\n Page Id:"
31+ print response ['json_data' ]['data' ][0 ]['id' ]
You can’t perform that action at this time.
0 commit comments