Created
May 28, 2019 20:20
-
-
Save lylayang/e8108ce20d14473bc90d0e4658edfac6 to your computer and use it in GitHub Desktop.
Get_fb_campaign_stats
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
''' | |
Refrence https://github.com/lylayang/facebook-python-ads-sdk | |
''' | |
from facebook_business.api import FacebookAdsApi | |
from facebook_business.adobjects.adaccount import AdAccount | |
from facebook_business.adobjects.adaccountuser import AdAccountUser | |
# Initialize a new Session and instantiate an API object: | |
my_app_id = 'YOUR APP ID' | |
my_app_secret = 'YOUR APP SECRET' | |
my_access_token = 'access_token could be get from Graph API Explorer: https://developers.facebook.com/tools/explorer/' | |
''' | |
also there are long lived user token and permantent token availiable. | |
use 'Access Token Debugger' to get your Access Token info | |
''' | |
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) | |
# List out all ad accounts under my ads manager | |
me=AdAccountUser(fbid= 'me') | |
all_accounts = list(me.get_ad_accounts()) | |
print(all_accounts) | |
print(type(all_accounts[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment