I'm walking through the marketing API quickstart and I am too the point where I have generated a user token with the graph api and then run the code below, but its telling me the token is invalid- I created it with all the permissions.
I can use the graph api with the same token to do a GET-> me/adaccounts and it works, but running Python on my PC does not.
#Add to header of your file
from facebookads.api import FacebookAdsApi
from facebookads import objects
#Initialize a new Session and instanciate an Api object
my_app_id = 'myappID'
my_app_secret = '{MySeceret}'
my_access_token = '{MyAccesstoken}'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
#Add to header of your file
from facebookads.objects import AdUser
#Add after FacebookAdsApi.init
me = AdUser(fbid='me')
my_account = me.get_ad_accounts()[0]
print my_account
THis is the error I get:
Press ENTER or type command to continue
Traceback (most recent call last):
File "fbapp.py", line 19, in <module>
my_account = me.get_ad_accounts()[0]
File "/home/morty/fbapp/facebookads/adobjects/helpers/adaccountusermixin.py", line 55, in get_ad_accounts
return self.iterate_edge(AdAccount, fields, params, endpoint='adaccounts')
File "/home/morty/fbapp/facebookads/adobjects/abstractcrudobject.py", line 539, in iterate_edge
cursor.load_next_page()
File "/home/morty/fbapp/facebookads/api.py", line 782, in load_next_page
params=self.params,
File "/home/morty/fbapp/facebookads/api.py", line 318, in call
raise fb_response.error()
facebookads.exceptions.FacebookRequestError:
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v2.6/me/adaccounts
Params: {'summary': 'true'}
Status: 400
Response:
{
"error": {
"message": "Invalid OAuth access token.",
"code": 190,
"type": "OAuthException",
"fbtrace_id": "Gop9F3vWJvk"
}
}
shell returned 1