I'm receiving a TwitterOAuthException when trying to implement a request_token & replicating the functionality of TwitterOAuth.
The error
The code I am using is as follows:
require_once $cfg['server']['root']."/inc/lib/tw/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', getenv('SlUlxP1lmXqqCCqoUOy0DGAL6'));
define('CONSUMER_SECRET', getenv('MM0vL2aRwp9rgS7qUF8UNEO3NtYv9W7QCZYSDzAyrZt7qa0XGg'));
define('OAUTH_CALLBACK', getenv('http://www.example-site.com/login/'));
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
pA($connection); //print connection contents
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
pA($request_token); //print connection contentsa
The output I get is:
Abraham\TwitterOAuth\TwitterOAuth Object
(
[response:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Response Object
(
[apiPath:Abraham\TwitterOAuth\Response:private] =>
[httpCode:Abraham\TwitterOAuth\Response:private] => 0
[headers:Abraham\TwitterOAuth\Response:private] => Array
(
)
[body:Abraham\TwitterOAuth\Response:private] => Array
(
)
[xHeaders:Abraham\TwitterOAuth\Response:private] => Array
(
)
)
[bearer:Abraham\TwitterOAuth\TwitterOAuth:private] =>
[consumer:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Consumer Object
(
[key] =>
[secret] =>
[callbackUrl] =>
)
[token:Abraham\TwitterOAuth\TwitterOAuth:private] =>
[signatureMethod:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\HmacSha1 Object
(
)
[timeout:protected] => 5
[connectionTimeout:protected] => 5
[decodeJsonAsArray:protected] =>
[userAgent:protected] => TwitterOAuth (+https://twitteroauth.com)
[proxy:protected] => Array
(
)
)
Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message '{"errors":[{"code":215,"message":"Bad Authentication data."}]}' in /home/user/public/test.com/public/inc/lib/tw/src/TwitterOAuth.php:137 Stack trace: #0 /home/chrismoore/public/trybe-ing.com/public/login/tw/tw_header.php(13): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...', Array) #1 /home/user/public/test.com/public/login/index.php(6): require_once('/home/user...') #2 {main} thrown in /home/user/public/test.com/public/inc/lib/tw/src/TwitterOAuth.php on line 137
Can anyone help me find a solution to this problem.
Thanks.