samwilson / phpflickr

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

Permission denied when trying to auth the user #7

Closed sfatfarma closed 5 years ago

sfatfarma commented 5 years ago

Hello,

I am getting a weird error when trying to auth with my app recently.

Permission denied Oops! You don't have permission to view this page.

The URL of it is: https://www.flickr.com/services/auth/?api_key=MY_API_KEY&perms=write&api_sig=MY_API_SIG

Do you have any idea on how to fix this or what might be wrong?

Thank you. Regards, Szabi.

willpower232 commented 5 years ago

You aren't using the oauth flow, re read https://github.com/samwilson/phpflickr/blob/master/README.md

sfatfarma commented 5 years ago

Hello,

Thank you @willpower232 for pointing this out.

My code is this:

        $f = new \Samwilson\PhpFlickr\PhpFlickr($api_key, $api_secret);
        $storage = new \OAuth\Common\Storage\Memory();
        $f->setOauthStorage($storage);
        $access_token = $f->retrieveAccessToken($_GET['oauth_verifier'], $_GET['oauth_token']);

The 2 URL parameters $_GET['oauth_verifier'], $_GET['oauth_token'] are correct. However, when I call the retrieveAccessToken method, I get this exception:

Token not stored

I checked the code and it seems that the retrieveAccessToken method expects the $storage parameter to already have an access token in it.

Code from OAuth\Common\Storage\Memory.php:

    public function retrieveAccessToken($service)
    {
        if ($this->hasAccessToken($service)) {
            return $this->tokens[$service];
        }

        throw new TokenNotFoundException('Token not stored');
    }

I am thinking that I am not using the correct version of \OAuth\Common\Storage\Memory() - right now I am using this: https://github.com/Lusitanian/PHPoAuthLib/blob/master/src/OAuth/Common/Storage/Memory.php

Is this correct? Thank you for the info!

Regards, Szabi.

sfatfarma commented 5 years ago

Got it.

$storage = new \OAuth\Common\Storage\Session();

Instead of:

$storage = new \OAuth\Common\Storage\Method();

Thank you, working.

Regards.

sfatfarma commented 5 years ago

Working. Thank you very much.