0

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
red888
  • 27,709
  • 55
  • 204
  • 392
  • _“I created it with all the permissions”_ – that has nothing to do with it, because for a missing permission you would get a different error message altogether. Your access token is invalid as the message says. So start by making a debug output of it, and put it through Facebook’s debug tool. – CBroe Apr 13 '16 at 17:41
  • Yeah did that and all the info looks correct. The appid matches and all of that. What else could it be? – red888 Apr 13 '16 at 20:21
  • Can you reproduce the result with the same request in Graph API Explorer, using the same access token? If so, and debug tool says it is still valid, then I’d file a bug report. (Include the `fbtrace_id` you get in the bug report, it helps them to trace it. And include your access token as well – but mark the bug as confidential.) – CBroe Apr 13 '16 at 20:28
  • Do I need to configure my app to use a website URL? I just want to call the API from my PC – red888 Apr 17 '16 at 12:58
  • I should say it works from the graph API – red888 Apr 17 '16 at 15:22

0 Answers0