繁体   English   中英

Twitter API中的“无法验证您”错误

[英]“Could not authenticate you” error from twitter API

我正在使用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"

我认为这不起作用,因为您不能将$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']);

让我知道是否可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM