Twitter身份验证:403禁止访问:服务器理解了该请求,但拒绝执行该请求 [英] Twitter authentication : 403 Forbidden: The server understood the request, but is refusing to fulfill it

查看:1316
本文介绍了Twitter身份验证:403禁止访问:服务器理解了该请求,但拒绝执行该请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OAuth验证用户身份并检索用户数据.当用户未登录Twitter时,身份验证有效,我可以获取用户详细信息.但是,如果用户已经在Twitter上登录,我会收到此错误消息"403 Forbidden:服务器理解了该请求,但拒绝执行该请求." .他们在一些帖子中说要通过https而不是http发出所有请求.我已经做到了.我已经从http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/下载了身份验证代码.请帮忙.

I am trying to authenticate user using OAuth and retrieve the user data. When the user is not signed into twitter the authentication works and I am able to get the user details. But if the user is already signed in on twitter I am getting this error message '403 Forbidden: The server understood the request, but is refusing to fulfill it.' . In some posts they said to make all the requests through https instead of http. That I have done. I have downloaded the code for authentication from 'http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/' . Please help.

$twitterOauthObj    =   new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
if(!isset($_GET['oauth_token'])){

    $requestTokenArray  =   $twitterOauthObj->getRequestToken($callback_url);
    $requestToken       =   $requestTokenArray['oauth_token'];
    $tokenSecret        =   $requestTokenArray['oauth_token_secret'];

    $authorizeUrl       =   $twitterOauthObj->getAuthorizeURL($requestToken);
    $response       =   $twitterOauthObj->oAuthRequest($authorizeUrl, 'GET', $requestTokenArray);
    print_r($response);
} else{

    $oauthToken     =   $_GET['oauth_token'];
    $requestToken       =   $oauthToken;
    $oauthVerifier      =   $_GET['oauth_verifier'];
    $accessTokenArray   =   $twitterOauthObj->getAccessToken($oauthVerifier, $oauthToken);
        $oauthToken     =   $accessTokenArray['oauth_token'];
    $oauthTokenSecret   =   $accessTokenArray['oauth_token_secret'];
    $userTwitterId      =   $accessTokenArray['user_id'];
    $screenName     =   $accessTokenArray['screen_name'];
 }

推荐答案

好.我知道了我没有重定向到正确授权URL.这是修改后的代码.

Ok. I got it working. I was not redirecting to authorize url correctly. Here is the modified code.

if(!isset($_GET['oauth_token'])){

    $requestToken   =   $twitterOauthObj->getRequestToken();
    $_SESSION["oauth_token"] = $requestToken["oauth_token"];
    $_SESSION["oauth_token_secret"] = $requestToken["oauth_token_secret"];

    header("Location:".$twitterOauthObj->getAuthorizeURL($requestToken["oauth_token"]));

}

感谢大家提出的所有宝贵建议.真的很感激!

Thank you guys for all your valuable suggestions. Really appreciate it!!

这篇关于Twitter身份验证:403禁止访问:服务器理解了该请求,但拒绝执行该请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆