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 推特 oauth。这在几周内运行良好,但现在得到的 http_code 为 0,甚至没有在 Twitter 的错误代码列表中列出。可能是什么问题呢

4

1 回答 1

1

这是我正在使用的片段,效果很好。

首先确保follownig 在开发推特中,您的应用程序可以读取/写入刷新消费者密钥,重新创建访问令牌。

如果以下方法不起作用,则问题出在其他地方 t 是别的东西!见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 回答