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

Not Getting "oauth_verifier" From $flickr->getAuthUrl($perm, $callbackUrl); #24

Closed testingCitytech closed 1 year ago

testingCitytech commented 5 years ago

This is my code:

`require_once 'vendor/autoload.php'; $apiKey = "6cc27cfb0c759011b11a48e456d8ba74"; $apiSecret = "6169a34168fae718"; $flickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret);

$storage = new \OAuth\Common\Storage\Memory(); $flickr->setOauthStorage($storage);

$perm = 'write'; $callbackUrl = false; $url = $flickr->getAuthUrl($perm, $callbackUrl);`

am not getting 'oauth_verifier' From $flickr->getAuthUrl($perm, $callbackUrl);

My Output

OAuth\Common\Http\Uri\Uri Object ( [scheme:OAuth\Common\Http\Uri\Uri:private] => https [userInfo:OAuth\Common\Http\Uri\Uri:private] => [rawUserInfo:OAuth\Common\Http\Uri\Uri:private] => [host:OAuth\Common\Http\Uri\Uri:private] => api.flickr.com [port:OAuth\Common\Http\Uri\Uri:private] => 443 [path:OAuth\Common\Http\Uri\Uri:private] => /services/oauth/authorize [query:OAuth\Common\Http\Uri\Uri:private] => oauth_token=72157710566803341-1250e3b8a7496c87&perms=write [fragment:OAuth\Common\Http\Uri\Uri:private] => [explicitPortSpecified:OAuth\Common\Http\Uri\Uri:private] => [explicitTrailingHostSlash:OAuth\Common\Http\Uri\Uri:private] => )

How to get 'oauth_token' from this array? demo php

samwilson commented 5 years ago

Your $url object is not an array, it's a \OAuth\Common\Http\Uri\Uri object. You normally don't need to get just the oauth_verifier value at this point, but rather the whole URL to which to send your user. This can be cast to a string, to get the full URL. You could for example redirect a web browser user like this:

header("Location: $url");
samwilson commented 5 years ago

(Oh, and you should delete your 6cc27cfb0c759011b11a48e456d8ba74 API key, as its secret has now been published publicly.)

testingCitytech commented 5 years ago

@samwilson Thank you. it is working but when I click "OK, I'LL AUTHORIZE IT" button not redirect to another page. Flickr  Authorize Upload Photo

Please help me... This API Key is invalid just for example.

samwilson commented 5 years ago

That's because you're passing false as the $callbackUrl. What happens when you try examples/get_auth_token.php in the browser? Does it work? That code adds a callback URL of itself. (Note that you need to create examples/config.php before using the examples.)

testingCitytech commented 5 years ago

This is index.php

require_once 'vendor/autoload.php'; $apiKey = "6cc27cfb0c759011b11a48e456d8ba8d"; $apiSecret = "6169a34168fae6b8"; $flickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret); $storage = new \OAuth\Common\Storage\Memory(); $flickr->setOauthStorage($storage); $perm = 'write'; $callbackUrl = 'http://localhost/flickr/vendor/samwilson/phpflickr/examples/get_auth_token.php'; $url = $flickr->getAuthUrl($perm, $callbackUrl); header("Location: $url");

Flickr  Authorize Upload Photo

This is examples/get_auth_token.php Getting accessToken & tokenSecret is blank, How to store accessToken & tokenSecret in session

$accessToken = ""; $accessTokenSecret = "";

Fatal error: Uncaught exception 'Samwilson\PhpFlickr\FlickrException' with message 'Unable to decode Flickr response to flickr.test.login request: oauth_problem=token_rejected' in C:\xampp\htdocs\flickr\vendor\samwilson\phpflickr\src\PhpFlickr.php:358 Stack trace: #0 C:\xampp\htdocs\flickr\vendor\samwilson\phpflickr\src\TestApi.php(31): Samwilson\PhpFlickr\PhpFlickr->request('flickr.test.log...', Array, true) #1 C:\xampp\htdocs\flickr\vendor\samwilson\phpflickr\examples\get_auth_token.php(63): Samwilson\PhpFlickr\TestApi->login() #2 {main} thrown in C:\xampp\htdocs\flickr\vendor\samwilson\phpflickr\src\PhpFlickr.php on line 358

Now what to do? Please help me.

samwilson commented 4 years ago

Did you create examples/config.php with valid values?

samwilson commented 2 years ago

Is this working now?