【问题标题】:What is wrong with this twitter authentication这个推特认证有什么问题
【发布时间】:2011-10-05 07:03:33
【问题描述】:

我有这段代码,但它没有执行。

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.');
}

有什么原因吗?

【问题讨论】:

  • 甚至没有错误?它什么都不做?
  • But the die('发生了错误。');被解雇
  • 所以它正在执行。您需要在 die 之前 var_dump($twitteroauth->http_code); 并查看打印出的值。
  • 错误:NULL 发生了错误。

标签: php twitter twitter-oauth


【解决方案1】:

Twitter Oauth 库和 API 不适用于 localhost URL。 您必须使用真实的 URL 而不是 localhost URL 向 Twitter 注册您的应用程序。

您可能应该使用一些托管服务,例如 Bluehost,然后针对 URL 注册您的应用程序。显然还有另一种方式 set up a virtual host 我没有亲自尝试过。但是你可以试一试。我不太确定它是否有效。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 2021-08-20
  • 2015-09-23
  • 2021-02-27
相关资源
最近更新 更多