2

我正在尝试为我的 Facebook 应用程序创建测试用户。他们在 11 月的这篇博客文章 (http://developers.facebook.com/blog/post/429) 中宣布了此功能,并在此处记录 ( http://developers.facebook.com/docs/test_users/ )。我在其他地方找不到这个问题的答案......

根据文档,“您可以使用带有应用程序访问令牌的 Graph API 创建与特定应用程序关联的测试用户。” 这链接到“作为应用程序进行身份验证”部分并描述了这个 CURL 脚本:

curl -F grant_type=client_credentials \
 -F client_id=your_app_id \
 -F client_secret=your_app_secret \
 https://graph.facebook.com/oauth/access_token

到目前为止,一切都很好。我运行它并得到以下信息:

access_token=1182...18|nTI...r5Q

所以现在我想将此令牌发布到图形 api 测试用户 URL:

POST /1182...18/accounts/test-users?installed=true&permissions=read_stream&access_token=1182...18|nTI...r5Q  

当我这样做时(都使用 Facebook PHP SDK 并且只是在浏览器中输入它)我得到:

{
    "error": {
      "type": "OAuthException",
      "message": "Invalid OAuth access token."
    }
}

所以问题是:

  • 为什么我会收到此错误消息?
  • 我是否使用了错误的访问令牌(尽管 Facebook 明确告诉我使用这个?)
  • 我是否需要以某种方式解析访问令牌?

    谢谢您的帮助。

  • 4

    3 回答 3

    2

    下面是一些工作代码,可让您使用 PHP SDK 创建测试用户。

    于 2011-01-04T13:30:06.267 回答
    0

    直到我从我看到浮动的示例代码中删除了一些参数,我才收到此错误。这是python中使用我最终设法开始工作的请求的示例:

    # Get the access token
    resp = requests.get(
        'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={app_id}&client_secret={app_secret}'.format(
            app_id=APP_ID, # Your app id (found in admin console)
            app_secret=APP_SECRET  # Your app secret (found in admin console)
        )
    )
    # Parse the token
    token = resp.content.split('=')[-1]
    
    # Create the user
    data = {'access_token': str(token)}
    resp = requests.post(
        'https://graph.facebook.com/{app_id}/accounts/test-users?installed=true'.format(
            app_id=APP_ID
        ),
        data=data
    )
    print resp.content
    
    于 2014-03-17T20:20:58.963 回答
    0

    确保您的访问令牌在传回 facebook 时已正确进行 urlencoded。

    于 2010-12-20T07:46:02.067 回答