Php 这个twitter身份验证有什么问题

Php 这个twitter身份验证有什么问题,php,twitter,twitter-oauth,Php,Twitter,Twitter Oauth,我有这个代码,但它没有执行 require_once('twitterOAuth.php'); session_start(); // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('consumerkey', 'consumersecret'); // Requesting authentication tokens, the parameter is the URL we will be redirected to $

我有这个代码,但它没有执行

require_once('twitterOAuth.php');
session_start();

// 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://localhost/tweet/twitterOAuth.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.');
}

有什么原因吗?

Twitter Oauth库和API不适用于本地主机URL。 您必须根据真实的URL而不是本地主机URL向Twitter注册应用程序。


您可能应该使用一些托管服务,比如Bluehost,然后根据URL注册您的应用程序。显然还有另一种方法我个人没有尝试过。但是你可以试一试。我不太确定它是否有效。

甚至没有错误?它什么也没做?但是死了(‘出了什么事’);是firedSo,所以它正在执行。您需要
var\u转储($twitterouth->http\u代码)
就在
死亡之前
并查看打印出的值。错误:NULL发生了错误。您是在虚拟主机或共享主机站点上尝试的吗?还有一件事就是不要选择代码。您应该指定您正在使用的Oauth库?显然,您正在使用Jaisen Mathai的Twitter异步库。如果您正在引用此库,您应该遵循这些教程-祝您好运-尝试一下