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

根据文档,“您可以使用与应用程序访问令牌的图形API创建与特定应用程序关联的测试用户。”这链接到“自动启用为应用程序”部分,并描述了此卷曲脚本:

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

因此,现在我想将此令牌发布到Graph 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明确告诉我使用它?)
  • 我需要以某种方式解析访问令牌吗?

    谢谢您的帮助。

  • 有帮助吗?

    解决方案

    这是一些 工作代码 这将使您可以使用PHP SDK创建测试用户。

    其他提示

    确保您的访问令牌在传递回Facebook时正确编码。

    我遇到了这个错误,直到我从浮动的示例代码中删除了一些参数为止。这是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
    
    许可以下: CC-BY-SA归因
    不隶属于 StackOverflow
    scroll top