bird-elephant icon indicating copy to clipboard operation
bird-elephant copied to clipboard

1.0a token is required to send tweet

Open earthwytch opened this issue 1 year ago • 3 comments

I have a 'this used to work' problem 😬 (sorry!) I am using Laravel to automate a tweet.

            $credentials = array(
                'consumer_key' => env('TWITTER_CONSUMER_KEY'),
                'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
                'bearer_token' => env('TWITTER_BEARER_TOKEN'),
                'auth_token' => $token,
            );
    
            $twitter = new BirdElephant($credentials);
            $tweet = (new Tweet)->text($tweetText);
            $tweetResult = $twitter->tweets()->tweet($tweet);

First, I started receiving 'Class "Coderjerk\BirdElephant\InvalidArgumentException" not found' when I tried to tweet. So to debug, I changed the following and then got the correct error message.

Coderjerk\BirdElephant\Request throw new \InvalidArgumentException('A 1.0a token is required for this endpoint.');

But I feel like I should actually be doing a bearerTokenRequest as I have successfully created an oAuth 2.0 auth_token. To test this I added $signed = false to Coderjerk\BirdElephant\Request and it all worked correctly - tweet was tweeted 🍾

Coderjerk\BirdElephant\Request

       $signed = false;

        if ($signed === true && (empty($this->credentials['token_identifier']) || empty($this->credentials['token_secret']))) {

            throw new \InvalidArgumentException('A 1.0a token is required for this endpoint.');

        }

        if ($signed === false && (isset($this->credentials['auth_token']) || isset($this->credentials['bearer_token'])) ) {

            return $this->bearerTokenRequest(
                $args,
                $this->credentials['auth_token'] ?? $this->credentials['bearer_token']
            );

        }

If the problem is that I genuinely am supposed to only use oAuth 1.0a then I can't understand why this worked before and why it works fine if I hack it to force $signed to be false. Am I missing an argument or something that tells it I want to use oAuth 2.0?

Thank you 🤸‍♀️

earthwytch avatar Jul 26 '23 19:07 earthwytch

Hi, could you let me know which version of birdelephant you're using? I'm guessing this is a side effect of #57 but would like to confirm first. if you're currently using v0.7 then can you try rolling back to 0.6.1 and let me know what happens?

danieldevine avatar Jul 26 '23 21:07 danieldevine

Yes, that was v0.7 and yes, it is fixed now I have rolled back to 0.6.1 ✔️

earthwytch avatar Jul 26 '23 21:07 earthwytch

ok, thanks very much for the report. I'll address the issue in the next release.

danieldevine avatar Jul 26 '23 21:07 danieldevine