Facebook OAuthException错误“无效的OAuth访问令牌”

时间:2016-04-13 11:49:52

标签: python facebook facebook-graph-api oauth

我正在浏览营销API快速入门,我太过分了,我已经用图形api生成了一个用户令牌,然后运行下面的代码,但它告诉我令牌无效 - 我用全部创建了它权限。

我可以使用带有相同令牌的图形api来执行GET->我/ adaccounts它可以工作,但在我的电脑上运行Python不会。

#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]

打印my_account

这是我得到的错误:

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

0 个答案:

没有答案