0

私のサイトでtwitterでのログインを有効にするこのコードがあります

<?php
require("twitter/twitteroauth.php");
require 'config/twconfig.php'; //CONTAINS CONSUMER SECRET AND CONSUMER KEY
session_start();

$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
$twitteroauth->host = "https://api.twitter.com/1.1/";
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://MY WEBSITE URL');

// Saving them into the session

$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

// If everything goes well..
if ($twitteroauth->http_code == 200) {
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: ' . $url);
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.'.$twitteroauth->http_code);
}
?>

私は Abraham Williams の twitter oauth を使用しています。これは数週間うまくいきましたが、現在、http_code が 0 になっています。これは、Twitter のエラー コード リストにも記載されていません。何が問題になる可能性がありますか

4

1 に答える 1

1

ここでは、私が使用している抜粋を示しますが、これは正常に機能します。

まず、次のことを確認してください。dev twitter では、アプリで読み取り/書き込みが可能です。コンシューマー キーの更新、アクセス トークンの再作成。

フォリングが機能しない場合、問題は別の場所にあります。https://dev.twitter.com/search/apachesolr_search/HTTP%20CODE%200を参照

指示を読んで、それに従ってください。あなたのコードが機能します

<?php
require_once('twitteroauth.php');  
session_start();  
/* 
 * INSTRUCTIONS!!!
 * https://dev.twitter.com/
 * create app
 * https://dev.twitter.com/ TAB settings 
 * website: THE_URL_TO_YOUR_SCRIPT_WITH_THIS_CODE
 * callback_url http://www.YOURDOMAIN.COM/ 
 * Read, Write and Access direct messages ! 
 * Allow this application to be used to Sign in with Twitter 
 * GO BACK TO DETAILS RECREATE / REFRESH - ACCESS TOKEN! 
 */

$consumerKey = '******************';
$consumerSecret = '******************';
$oAuthToken = '*********************';
$oAuthSecret = '**************************';

// The TwitterOAuth instance  
$twitteroauth = new TwitterOAuth($consumerKey, $consumerSecret);  
// Requesting authentication tokens, the parameter is the URL we will be redirected to  
$request_token = $twitteroauth->getRequestToken('http://DOMAIN.com/YOURLOGINSCRIPT.php');  

// Saving them into the session  
$_SESSION['oauth_token'] = $request_token['oauth_token'];  
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];  

// If everything goes well..  
if($twitteroauth->http_code==200){  
    // Let's generate the URL and redirect  
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: '. $url);
} else { 
    // It's a bad idea to kill the script, but we've got to know when there's an error.  
    die('Something wrong happened.');  
}  
?>
于 2013-06-14T19:59:04.917 に答える