【问题标题】:Problem with access token while creating Facebook Test Users创建 Facebook 测试用户时访问令牌出现问题
【发布时间】:2011-05-27 23:31:11
【问题描述】:

我正在尝试为我的 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 明确告诉我使用这个?)
  • 我是否需要以某种方式解析访问令牌?

    感谢您的帮助。

  • 【问题讨论】:

      标签: php facebook facebook-graph-api access-token


      【解决方案1】:

      这里有一些working code,可让您使用 PHP SDK 创建测试用户。

      【讨论】:

      • 谢谢,我实现了类似的东西,它可以工作。
      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        在我从我看到的浮动示例代码中删除了一些参数之前,我收到了这个错误。这是一个使用我最终设法开始工作的请求的 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
        

        【讨论】:

          猜你喜欢
          • 2013-01-13
          • 1970-01-01
          • 2011-11-07
          • 1970-01-01
          • 2016-08-30
          • 2011-12-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多