![](/img/trans.png)
[英]Completely stuck trying to use Abraham Williams Twitter API libraries
[英]Unable to use Abraham Twitter API SDK
我正在使用Abraham Twitter API SDK,并且在执行index.php页面时遇到一些问题。 在我的config.php页面中,我的代码是这样的
define('CONSUMER_KEY', 'xxxxxxxxxxxxxxxxxxxxxx');
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('OAUTH_CALLBACK', 'http://example.com/callback.php');
当我在浏览器中打开索引文件时,它将重定向到connect.php。在这里,如果单击“ Signin with PHP
按钮,则页面将重定向到这里的redirect.php,这是我的问题。 在redirect.php页面中,我包含twitteroauth.php文件。
我的redirect.php文件中的代码
/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
case 200:
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->getAuthorizeURL($token);
header('Location: ' . $url);
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
在我的twitteroauth.php文件中,构造函数如下所示
function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
$this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
if (!empty($oauth_token) && !empty($oauth_token_secret)) {
$this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
} else {
$this->token = NULL;
}
}
我在浏览器中遇到的错误是
Notice: Undefined index: oauth_token in line 80
Could not connect to Twitter. Refresh the page or try again later.
我尝试了多种方法来解决此问题。 但是我失败了。 请帮助我。 提前致谢。
我有类似的错误。 我通过在Twitter应用程序设置中设置回调URL来解决该问题。 http://dev.twitter.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.