abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.29k stars 1.71k forks source link

Arrays not supported in headers ? #337

Closed Mendi33 closed 9 years ago

Mendi33 commented 9 years ago

Hi, after getting user's authorization, here's my callback page :

$access_token = $_SESSION['oauth_token'];
$access_token_secret = $_SESSION['oauth_token_secret'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);

$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_GET['oauth_verifier']));
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);

Then, every request i make like :

$media = $connection->upload('media/upload', array('media' => '../images/4ebead25b440aecfda97c20eb51dca14.png'));
$statuses = $connection->get("search/tweets", array("q" => "twitterapi"));
$statues = $connection->post("statuses/update", array("status" => "hello world"));

returns me a Fatal Error : Arrays not supported in headers

Here it is in full text :

Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message 'Arrays not supported in headers' in /homepages/5/d370210404/htdocs/printShootHTTP/twitter/twitteroauth/src/Request.php:227 Stack trace: #0 /homepages/5/d370210404/htdocs/printShootHTTP/twitter/twitteroauth/src/TwitterOAuth.php(247): Abraham\TwitterOAuth\Request->toHeader() #1 /homepages/5/d370210404/htdocs/printShootHTTP/twitter/twitteroauth/src/TwitterOAuth.php(222): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest('https://api.twi...', 'GET', Array) #2 /homepages/5/d370210404/htdocs/printShootHTTP/twitter/twitteroauth/src/TwitterOAuth.php(177): Abraham\TwitterOAuth\TwitterOAuth->http('GET', 'https://api.twi...', 'search/tweets', Array) #3 /homepages/5/d370210404/htdocs/printShootHTTP/twitter/callback.php(32): Abraham\TwitterOAuth\TwitterOAuth->get('search/tweets', Array) #4 {main} thrown in /homepages/5/d370210404/htdocs/printShootHTTP/twitter/twitteroauth/src/Request.php on line 227

I don't understand this one ! Any thoughts ??

abraham commented 9 years ago

You are overwriting variables with different value types. $access_token starts as the oauth_token string from the session but when you make the oauth/access_token request you set the value to the response which is an object.

$access_token = $_SESSION['oauth_token'];
$access_token_secret = $_SESSION['oauth_token_secret'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);

$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_GET['oauth_verifier']));
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);

You should be better with variable names but in short change the last line to this:

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
Mendi33 commented 9 years ago

... gooood. Waiting for the week end to refuel. Thanks ;)