TwitterOAuth - 无法验证 oauth 签名和令牌


TwitterOAuth - Failed to validate oauth signature and token

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

致命错误:未捕获的异常"Abraham''TwitterOAuth''TwitterOAuthException",消息"无法验证 oauth 签名和令牌"在/home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php:221 堆栈跟踪:#0/home/kp/domains/konradprzydzial

.pl/public_html/tweetupchat/login.php(10): Abraham''TwitterOAuth''TwitterOAuth->oauth('oauth/request_t...', Array) #1 {main} throw in/home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php 在第 221 行

我在此文件中的代码:

<?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是正确的。问题出在哪里?

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

您在此处的代码看起来不错。但是,如果您使用的是亚伯拉罕在 https://twitteroauth.com/redirect.php 上提供的文档,那么一种解决方案是删除CONSUMER_KEY周围的getenv()函数并CONSUMER_SECRET

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

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

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

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