簡體   English   中英

無法使用Abraham Twitter API SDK

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM