samwilson / phpflickr

A PHP wrapper for the Flickr API, including OAuth.
https://packagist.org/packages/samwilson/phpflickr
GNU General Public License v2.0
39 stars 15 forks source link

Fatal error when trying to run get_auth_token.php in examples #34

Closed kdswoods closed 1 year ago

kdswoods commented 4 years ago

Relatively new to this, so it may be something simple I'm missing, but I've copied the config.php file and updated the $apiKey and $apiSecret with my own, and can run the unauthenticated_requests.php example, but when trying to run the get_auth_token.php file, it returns:

Fatal error: Uncaught OAuth\Common\Http\Exception\TokenResponseException: Error in retrieving token. in C:\xampp\htdocs\photos\vendor\lusitanian\oauth\src\OAuth\OAuth1\Service\Flickr.php:52 Stack trace: #0 C:\xampp\htdocs\photos\vendor\lusitanian\oauth\src\OAuth\OAuth1\Service\AbstractService.php(54): OAuth\OAuth1\Service\Flickr->parseRequestTokenResponse('oauth_problem=s...') #1 C:\xampp\htdocs\photos\vendor\samwilson\phpflickr\src\PhpFlickr.php(560): OAuth\OAuth1\Service\AbstractService->requestRequestToken() #2 C:\xampp\htdocs\photos\examples\get_auth_token.php(32): Samwilson\PhpFlickr\PhpFlickr->getAuthUrl('delete', 'http://localhos...') #3 {main} thrown in C:\xampp\htdocs\photos\vendor\lusitanian\oauth\src\OAuth\OAuth1\Service\Flickr.php on line 52

Any thoughts on what could be causing this?

samwilson commented 4 years ago

This error is before it's presented you with a URL at all isn't it? It sounds like it might be an error with the $apiSecret: are there any trailing slashes or anything?

kdswoods commented 4 years ago

Correct, it throws the error immediately on accessing the page. Nothing seems off with the key or secret, just an alphanumeric string for each.

samwilson commented 4 years ago

The code in question is

        $callbackHere = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        $url = $flickr->getAuthUrl('delete', $callbackHere);

What web server are you using? Is the callback being constructed correctly? What if you change the requested permission to 'read'?

Is the API consumer disabled? Is its 'authentication flow' set to 'web'?

Umm. I don't know what else to check. :) I'm sure we can figure it out though!

kdswoods commented 4 years ago

Interesting. I was running this on localhost (making a raspberry pi-powered photoframe) and it was throwing the error. Based on your question, I uploaded the files to my public server and it worked. Do you think it's a problem running on localhost, or would it be my local server configuration?

samwilson commented 4 years ago

It sounds like wherever you're running it from doesn't have access to flickr.com. I'm not sure what would be causing that, sorry.