Facebook OAuthException error “Invalid OAuth access token”

坚强是说给别人听的谎言 提交于 2020-01-07 06:36:23

问题


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

来源:https://stackoverflow.com/questions/36597474/facebook-oauthexception-error-invalid-oauth-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!