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

token_rejected #21

Closed ylegrand closed 5 years ago

ylegrand commented 5 years ago

Hello,

Im' facing to an issue when I try to authentificate with oAuth. I manage to get a couple of token/verifier back from FlickR in my web app (under development, so hosted in my localhost).

But unfortunately, when I try the method retrieveAccessToken(), I get a "token_rejected" error, and 4 notices like Notice: Undefined index: oauth_token in C:\wamp64\www\flickr\vendor\lusitanian\oauth\src\OAuth\OAuth1\Service\Flickr.php on line 67

Is there someting I missed? Any help is appreciated :-)

My full code below :

<?php 
    session_start();

    // OBJET FLICKR
    // ------------
    require_once 'vendor/autoload.php';

    $apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    $apiSecretKey = "yyyyyyyyyyyyyyyy";

    $f = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecretKey);
    $storage = new \OAuth\Common\Storage\Session();
    $f->setOauthStorage($storage);

    // SESSION STORING
    // ---------------
    if(isset($_GET['oauth_verifier']))
        $_SESSION['oauth_verifier'] = $_GET['oauth_verifier'];

    if(isset($_GET['oauth_token']))
        $_SESSION['oauth_token'] = $_GET['oauth_token'];

    // GENERATE TOKEN IF NEEDED
    // ------------------------
    if(!isset($_SESSION['oauth_verifier'])){

        $perm = 'read';
        $callbackUrl = null;    // Renvoie vers la même page
        $url = $f->getAuthUrl($perm, $callbackUrl);
        header('Location: '.$url->getAbsoluteUri());

    // CONNEXION WITH TOKEN
    // --------------------
    } else{
        $accessToken = $f->retrieveAccessToken($_SESSION['oauth_verifier'], $_SESSION['oauth_token']);
        var_dump($accessToken);
    }

Thanks !

ylegrand commented 5 years ago

Hi there!

I am sorry to repost without being able to provide any further information, but unfortunately I am still stuck at the same point.

Is there any information I could provide to help understand my problem? Could it be linked to a setting of my FlickR account or a property of my API key?

Thanks in advance for your time.

samwilson commented 5 years ago

Sorry about the delay in replying.

You don't need to manually set the session values.

Have a look at the code in the "web-browser workflow" part of examples/get_auth_token.php:

https://github.com/samwilson/phpflickr/blob/e409aa5516eb21b663dbe58aa5415cf469a8d8f7/examples/get_auth_token.php#L23-L37

ylegrand commented 5 years ago

Good evening,

It seems that I have an unfortunate tendency to try to reinvent the wheel... and not read the documentation properly.

I'm now able to connect :-) Thanks a lot for your support, and for the work involved in this project.

samwilson commented 5 years ago

No worries! I'm glad it works. And you're a programmer, you're supposed to not read the docs first. ;-)