dongsha2792
2011-11-20 22:02 阅读 124

来自twitter API的“无法验证您”错误

I'm using Abhraham's twitter API library.

My index.php

<?php
ob_start();
session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'twitteroauth/OAuth.php';
define("CONSUMER_KEY", "");
define("CONSUMER_SECRET", "");
$to = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
$request_link = $to->getAuthorizeURL($tok);
$_SESSION['oauth_access_token']= $tok['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
header("Location: $request_link");
exit;
?>

My redirect.php

<?php
ob_start();
session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'twitteroauth/OAuth.php';
define("CONSUMER_KEY", "");
define("CONSUMER_SECRET", "");

$to=new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$_SESSION['oauth_access_token'],$_SESSION['oauth_access_token_secret']);
$content = $to->get('account/verify_credentials');
var_dump($content);
?>

But I dont understant why I'm getting "Could not authenticate you" on the redirect.php page

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douciwang6819 douciwang6819 2011-11-21 15:58

    I think this doesn't work because you cannot put $tok directly in the getAuthrorizeURL() function:

    $tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
    $request_link = $to->getAuthorizeURL($tok);
    

    You need to extract the token from $tok['oauth_token']:

    $tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
    $request_link = $to->getAuthorizeURL($tok['oauth_token']);
    

    Let me know if this fixes it.

    点赞 评论 复制链接分享

相关推荐