jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
775 stars 237 forks source link

Fatal error using example authorization code on a private network #236

Closed lordmatt closed 5 years ago

lordmatt commented 6 years ago

I am attempting to use your example code to authorise a user (other than the one carrying the app credentials) and I have run into an error I cnnot overcome.

Notice:  Undefined property: stdClass::$oauth_token in /var/www/html/authorise.php on line 29
Notice:  Undefined property: stdClass::$oauth_token_secret in /var/www/html/authorise.php on line 29
Notice:  Undefined property: stdClass::$oauth_token in /var/www/html/authorise.php on line 30
Notice:  Undefined property: stdClass::$oauth_token_secret in /var/www/html/authorise.php on line 31

Fatal error:  Uncaught exception 'Codebird\CodebirdCredentialsException' with message 'To get the authorize URL, the OAuth token must be set.' in /var/www/html/codebird/codebird.php:1048
Stack trace:
#0 /var/www/html/codebird/codebird.php(1069): Codebird\Codebird->oauth_authenticate(NULL, NULL, 'authorize')
#1 /var/www/html/authorise.php(37): Codebird\Codebird->oauth_authorize()
#2 {main}
  thrown in /var/www/html/codebird/codebird.php on line 1048
lordmatt commented 6 years ago

As far as I can tell oauth_requestToken sets the tokens to null and to null they stay.

lordmatt commented 6 years ago

Tested with dev and master branches.

kylex commented 6 years ago

@lordmatt I noticed this started happening recently to my code as well. It appears that Twitter has tightened up their security and now the authorized callback URLs must match perfectly: https://apps.twitter.com/app/YOUR-APP-ID/settings

In my case, I wasn't using 'www' as the subdomain even though the TLD was the same. Seems to be a relatively new issue. Hope that helps you.

martinlugton commented 5 years ago

This was my experience too. kylex's fix worked for me - going to twitter.com and updating the callback URL so that it matched perfectly. Thanks @kylex !