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.
私はこの問題を解決するために多くの方法を試しました。しかし、私は失敗しました。その中で私を助けてください。前もって感謝します。