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

Help please, I have problems with sync_upload #6

Closed hectorzapata closed 5 years ago

hectorzapata commented 6 years ago

Hello, first of all I appreciate your support. I have been trying to upload an image using Laravel 5.6, I have generated the accessToken and accessTokenSecret with the permission 'delete' and when I try it returns me "The Flickr API returned the following error: # 99 - Insufficient permissions Method requires write privileges; none . " I really do not know what I'm doing wrong, I also call the getRecent method and it works without problems which makes me think that the authentication is also correct.

I leave my code:

image

Response:

image

I should also mention that I changed the 436 line of the PHPFlickr.php file: image

by: image

Because I was returning the following error: image

I really hope you can help me, thank you very much, regards

lastcoolnameleft commented 6 years ago

I'm experiencing the same issue, did you find a solution for it, @hectorzapata ?

Thanks for suggesting the new \CURLFile line as I also hit that problem too with the signature.

hectorzapata commented 6 years ago

Yes, i found this tutorial http://www.developpeur-web.dantsu.com/fr/cours-tutoriels/flickr/a_authenticate-to-flickr-api-with-oauth-and-phpflickr, regards

samwilson commented 6 years ago

I'm very sorry about this bug. I'll try to get it sorted and the docs updated, this weekend. :)

bart-d commented 6 years ago

i'm down the same path. I had to replace the $args to new \CURLFile to get by the invalid signature. Now I have the same 'insufficient privileges' error while i went through get_auth_token.php to get write and even delete privileges.

I also don't see how the other phpflickr/oauth instructions would help here. It's basically creating the same tokens.

willpower232 commented 5 years ago

The problem is this function is lacking the oauth parameters completely so flickr is rejecting it by saying you have no permissions at all as there is no token in the request.

As flickr uploads to a completely different URL, I don't think there is a way within the current oauth library dependency to accomplish what we need but you can add a function into the package manually and update the phpflickr library yourself to use it.

In vendor/lusitanian/oauth/src/OAuth/OAuth1/Service/Flickr.php add this function to the class

    public function getAuthorizationForPostingToAlternateURL($args, $urioverride)
    {
        $token = $this->storage->retrieveAccessToken($this->service());

        $this->signature->setTokenSecret($token->getAccessTokenSecret());
        $authParameters = $this->getBasicAuthorizationHeaderInfo();
        if (isset($authParameters['oauth_callback'])) {
            unset($authParameters['oauth_callback']);
        }

        $authParameters = array_merge($authParameters, array('oauth_token' => $token->getAccessToken()));

        $signatureParams = array_merge($authParameters, $args);

        $authParameters['oauth_signature'] = $this->signature->getSignature(new Uri($urioverride), $signatureParams);

        return array_merge($authParameters, $args);
    }

I borrowed those lines from buildAuthorizationHeaderForAPIRequest in vendor/lusitanian/oauth/src/OAuth/OAuth1/Service/AbstractService.php.

To update phpflickr, the lines around realpath($photo) need to look like this

    $oauthService = $this->getOauthService();
    $args = $oauthService->getAuthorizationForPostingToAlternateURL($args, $this->upload_endpoint);

    // if (!empty($this->secret)) {
    //     $api_sig = md5($this->secret . $auth_sig);
    //     $args["api_sig"] = $api_sig;
    // }

    $photo = realpath($photo);
    $args['photo'] = new \Curlfile($photo);

I don't know the best way to proceed from here @samwilson, hopefully you have a cleverer way than I!

sfatfarma commented 5 years ago

The above worked for me also. Thank you very much!

samwilson commented 5 years ago

I'm fixing this now. See #10

Sorry for the very slow response! :)

sfatfarma commented 5 years ago

Thank you.