需要有关 OAuthException 代码 2500 的帮助

Need Help on OAuthException Code 2500(需要有关 OAuthException 代码 2500 的帮助)
本文介绍了需要有关 OAuthException 代码 2500 的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 PHP 开发 Facebook 应用程序 (apps.facebook.com/some_app),我需要根据用户的音乐兴趣提供一些信息.我发现它在user_likes > games"下.

我的问题如下:

  • 为了获得访问权限,我已将 oauth 对话框方法实现为在我的索引页面的 API 中建议.
<小时>

$auth_url = "http://www.facebook.com/dialog/oauth?client_id=".$app_id ."&redirect_uri=".urlencode($canvas_page)."&scope=user_likes";

  • 授权成功后,我回到带有代码"的索引页面作为参数.
<小时>

http://MY_CANVAS_PAGE/?code=一些 base64 编码的字母

  • 首先我不知道我是否需要 access_token 来读取用户的音乐兴趣,但我已经尝试了所有建议的方法.我动不了从这里开始
  • 我有一个这样的代码(在我的索引页面中),如果没有设置代码参数,它会重定向以进行授权.
<小时>

if(empty($code) && !isset($_REQUEST['error'])) {$_SESSION['state'] = md5(uniqid(rand(), TRUE));//CSRF保护echo("<script> top.location.href='" . $auth_url . "'</script>");}

  • 目前我只是想在这里获取用户的公开信息,但是没有成功.我已经按照建议尝试了 signed_request 方法但没有成功
<小时>

$signed_request = $_REQUEST["signed_request"];列表($encoded_sig, $payload) = expand('.', $signed_request, 2);$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);echo ("欢迎用户:" . $data["user_id"]);

  • 还尝试了在http://developers.facebook.com/blog/post/500/>

    但是在尝试使用

  • 获取调试信息时出现错误
<小时>

print_r($decoded_response);

<小时>

stdClass Object ( [error] => stdClass Object ( [message] => 一个活动必须使用访问令牌来查询有关当前用户的信息.[类型] =>OAuthException [代码] =>2500 ) )

为了获取用户的公开信息,我也尝试了 PHP SDK 中的建议示例

<小时>

$facebook = new Facebook(array('appId' =>MY_APP_ID,//注册的facebook APP ID'秘密' =>MY_SECRET,//APP的秘钥));$fb_user = $facebook->getUser();如果($ fb_user){尝试 {$user_profile = $facebook->api('/me');回声 $user_profile['email'];}抓住(FacebookApiException $e){$fb_user = null;}}

但没有成功.有人可以解释我为什么会收到此错误以及如何正确访问用户的音乐兴趣.可能我误解了 API.

谢谢

Deepak

解决方案

Error 2500 表示您没有访问令牌或应用程序访问令牌但正在尝试访问 /me/ - 'me' 是当前用户或页面 ID"的占位符,因此在没有用户或页面的访问令牌的情况下无效.

要访问用户的喜欢列表,您还需要 user_likes 权限 授权他们

我见过的应用程序无法将 code 交换为访问令牌的最可能原因是:

  1. 您使用的 redirect_uri 指向文件夹或服务器根目录,并且缺少尾部斜杠(即它是 http://www.example.com 而不是 http://www.example.com/)
  2. 您在第一次调用身份验证对话框时使用的 redirect_uri 与您在调用中用于交换 access_token 代码的 redirect_uri 并不完全相同

如果您的身份验证流程因其他原因而中断,并且您无法从 SDK 示例或 身份验证 文档,这可能需要一段时间才能让某人与您交谈,因为您可能缺少理解他们的答案所必需的一些背景知识

I am trying to develop an Facebook application (apps.facebook.com/some_app) using PHP where I need to present some information based on user's music interests. I found that its under "user_likes > games".

My problems are as follows:

  • To gain access, I have implemented the oauth dialog method as suggested in API in my index page.

$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
            . $app_id . "&redirect_uri=" 
            . urlencode($canvas_page)
            ."&scope=user_likes";

  • After successful authorization I come back to index page with "code" as parameters.

http://MY_CANVAS_PAGE/?code=some base64 encoded letters

  • Firstly I don't know if I need access_token just to read user's music interests but I have tried all the methods suggested. I couldn't move forward from this point
  • I have a code like this (in my index page), which redirects for authorization if code parameters is not set.

if(empty($code) && !isset($_REQUEST['error'])) {
  $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
  echo("<script> top.location.href='" . $auth_url . "'</script>");
}

  • Currently I am just trying to get user's public information here but with no success. I have tried the signed_request method as suggested but no success

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
echo ("Welcome User: " . $data["user_id"]);

  • Also tried the code found in http://developers.facebook.com/blog/post/500/

    but I am getting error when trying to get the debug info using


print_r($decoded_response);


stdClass Object ( [error] => stdClass Object ( [message] => An active 
access token must be used to query information about the current user. 
[type] => OAuthException [code] => 2500 ) ) 

To get user's public info, I have tried also the suggested example in PHP SDK


$facebook = new Facebook(array(
'appId'  => MY_APP_ID, //registered facebook APP ID
'secret' => MY_SECRET, //secret key for APP
));

$fb_user = $facebook->getUser();

if($fb_user){
    try {
      $user_profile = $facebook->api('/me');
      echo $user_profile['email'];
    }
    catch(FacebookApiException $e) {
      $fb_user = null;
    }
}

But no success. Can somebody explain me why I am getting this error and how to access the user's music interest properly. Probably I misunderstood the API.

Thanks

Deepak

解决方案

Error 2500 means you have no access token or an app access token but are trying to access /me/ - 'me' is a placeholder for 'current user or page ID' so won't be valid without an access token for a user or page.

To access the user's list of likes you'll also need the user_likes Permission when authorising them

The most likely causes i've seen for apps not being able to exchange the code for an access token are:

  1. The redirect_uri you used is to a folder or server root and is missing a trailing slash (i.e it's http://www.example.com instead of http://www.example.com/)
  2. The redirect_uri you used in the first call to the auth dialog wasn't precisely the same as the redirect_uri you used in the call to exchagne the code for an access_token

If your auth flow is broken for some other reason and you can't figure it out from the SDK examples or the Authentication documentation, this could take a while for someone to talk you through because you may be missing some background knowledge necessary to understand their answers

这篇关于需要有关 OAuthException 代码 2500 的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)