【问题标题】:Unable to use Abraham Twitter API SDK无法使用亚伯拉罕推特 API SDK
【发布时间】:2014-07-21 07:58:19
【问题描述】:

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

我尝试了很多方法来解决这个问题。但我失败了。 请帮助我。 提前致谢。

【问题讨论】:

    标签: php api redirect twitter


    【解决方案1】:

    我有类似的错误。我通过在我的 twitter 应用程序设置中设置回调 URL 来解决它。 http://dev.twitter.com

    【讨论】:

    • 我得到了完全相同的错误。您能否详细说明您是如何解决该错误的。
    • @ArchitVerma 我已经编辑了上面的答案。请检查一下。希望现在更清楚了。
    猜你喜欢
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多