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

时间:2011-11-20 22:02:14

标签: php api twitter

我正在使用Abhraham的twitter API库。

我的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;
?>

我的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);
?>

但我不明白为什么我在redirect.php页面上获得"Could not authenticate you"

1 个答案:

答案 0 :(得分:0)

我认为这不起作用,因为您无法将$tok直接放在getAuthrorizeURL()函数中:

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

您需要从$tok['oauth_token']提取令牌:

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

请告诉我这是否可以解决问题。