【问题标题】:TwitterOAuth - Failed to validate oauth signature and tokenTwitterOAuth - 无法验证 oauth 签名和令牌
【发布时间】:2015-03-19 07:42:26
【问题描述】:

我正在尝试使用 Twitter OAuth 制作 PHP 应用程序。在我的代码中,我使用了 twitteroauth 库。我试图像在图书馆教程中一样进行授权,但是当我尝试制作请求令牌时,我收到了这个错误:

致命错误:在 /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/ 中出现消息“无法验证 oauth 签名和令牌”的未捕获异常“Abraham\TwitterOAuth\TwitterOAuthException” TwitterOAuth.php:221 堆栈跟踪:#0 /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/login.php(10): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...',数组)#1 {main} 在第 221 行的 /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php 中抛出

我在这个文件中的代码:

<?php

require "vendor/autoload.php";
require "config.php";

use Abraham\TwitterOAuth\TwitterOAuth;

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));

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

var_dump($request_token['oauth_token']);
var_dump($request_token['oauth_token_secret']);

$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));

echo '<a href="'.$url.'">Zaloguj się</a>';

?>

CONSUMER_KEY 和 CONSUMER_SECRET 是正确的。问题出在哪里?

【问题讨论】:

  • 您是否在对象实例化之前转储了消费者值只是为了再次检查它们是否正确?另外,您计算机的系统时钟设置是否正确?如果您的 >~5 分钟不同步,Twitter 将会失败。
  • 我把它扔了,它是正确的。我使用共享主机。服务器时间比 Twitter API 状态下的时间提前 2 分钟。

标签: php twitter oauth


【解决方案1】:

我还在为 twitter API 使用 abraham/twitteroauth 包装器并遇到了同样的问题。

这里的代码看起来不错。但是,如果您使用的是 abraham 在 https://twitteroauth.com/redirect.php 上提供的文档,那么一种解决方案是删除 CONSUMER_KEYCONSUMER_SECRET 周围的 getenv() 函数。

我只能推测,因为我不知道您的 config.php 文件中使用的代码,但我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我认为是 CURL 问题 尝试检查他们是否传递了正确的参数

    abraham\twitteroauth\src\TwitterOAuth.php 在第 348 行

    function request($url, $method, $headers, $postfields)
    

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多