Reputation: 296
I'm trying to make PHP application with Twitter OAuth. In my code I used twitteroauth library. I was trying to make authorization like in library tutorial but I when I try make request token I get this error:
Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message 'Failed to validate oauth signature and token' in /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php:221 Stack trace: #0 /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/login.php(10): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...', Array) #1 {main} thrown in /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php on line 221
My code in this file:
<?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 and CONSUMER_SECRET are correct. Where is the problem?
Upvotes: 1
Views: 1077
Reputation: 11
I think it's the CURL problem try check if they passing the right parameter
abraham\twitteroauth\src\TwitterOAuth.php at line 348
function request($url, $method, $headers, $postfields)
Upvotes: 1
Reputation: 21
I am also using the abraham/twitteroauth wrapper for the twitter API and ran into the same problem.
The code you have here looks good. However, if you were using the documentation that was given by abraham on https://twitteroauth.com/redirect.php, then one solution is to remove the getenv()
function around the CONSUMER_KEY
and CONSUMER_SECRET
.
I can only speculate as I do not know the code used in your config.php file, but I hope this helps.
Upvotes: 2