sybrenstuvel/flickrapi

No token after authentication.

rispoli opened this issue · 10 comments

Hi all. Was trying to authenticate my custom application following some examples but couldn't get it to work.
Would you please point me to my mistake?

I tried:

import flickrapi

API_KEY = "..."
API_SECRET = "..."

flickr = flickrapi.FlickrAPI(API_KEY, API_SECRET)
flickr.authenticate_console(perms='delete')
print "delete?"
print flickr.token_valid(perms='delete')
print flickr.token_cache.token

and also authenticate_via_browser instead of authenticate_console but, in both cases, the last two print returns:

False
None

while no error with the browser interaction is ever shown.

I also tried the longer:

import flickrapi

API_KEY = "..."
API_SECRET = "..."

flickr = flickrapi.FlickrAPI(API_KEY, API_SECRET)

print "delete?"
print flickr.token_valid(perms='delete')

flickr.get_request_token(oauth_callback='oob')

authorize_url = flickr.auth_url(perms=u'delete')
print(authorize_url)

verifier = unicode(raw_input('Verifier code: '))
print "Verifier:", verifier

print(flickr.get_access_token(verifier))

print "delete?"
print flickr.token_valid(perms='delete')
print flickr.token_cache.token

which, unfortunately, results in exactly the same outcome.

Could you, please, help me out with this authentication issue?
I just need a token number that I can store somewhere to be read afterwards.

Thanks in advance,
Daniele

Your initial script works fine for me, using Python 2.7.9 (I'm assuming you're using 2.7 because your print statements are invalid in Python 3.x). This is my output:

% python issue-92.py
Go to the following link in your browser to authorize this application:
https://www.flickr.com/services/oauth/authorize?oauth_token=72157688831940136-xxxxxxxxxxxxxxxx&perms=delete
()
127.0.0.1 - - [26/Sep/2017 13:39:38] "GET /?oauth_token=72157688831940136-xxxxxxxxxxxxxxxx&oauth_verifier=yyyyyyyyyyyyyyyy HTTP/1.1" 200 -
delete?
True
FlickrAccessToken(token=72157630408061838-xxxxxxxxxxxxxxxx, fullname=Sybren Stüvel, username=Sybren A. Stüvel, user_nsid=73xxxxxx@N00)

Which version of Python are you using?

@sybrenstuvel: thanks for your answer.
I'm using version 2.7.12 of Python and you're right. It does work but only after deleting the previous authorization I had grated to my application.

Just to confirm: now I can copy the token "number" and re-use it without having to authorize the application again, right?

I'm using version 2.7.12 of Python

Just out of curiousity: why are you still using 2.7?

It does work but only after deleting the previous authorization I had grated to my application.

That is strange, but I'm glad it works now.

Just to confirm: now I can copy the token "number" and re-use it without having to authorize the application again, right?

Correct.

I'm still on Python 2.7 because I was just trying to patch an existing application, flickr-uploadr, which I didn't write.

Unfortuntely, I still get:

{'nojsoncallback': '1', 'format': 'json', 'perms': '', 'auth_token': 'abc-xyz', 'api_sig': '...', 'api_key': '...', 'method': 'flickr.photosets.getList'}
Error: {u'stat': u'fail', u'code': 98, u'message': u'Invalid auth token'}

Provide example code that actually matches your situation. You're apparently using the JSON format in your code, whereas in the original example you do not.

Here's the code:
https://pastebin.com/xwxTFVef

I had downloaded it from somewhere but I can't find the original source.
The weird thing is: with an account that I had authorized before Flickr changed the authentication scheme it still works fine. Trying with this new account, I can't manage to make it work.

Any idea? I find it quite curious that it keeps working with an account authorized previously but not if I try now.

Hello @rispoli, the code you reference seems to be the same as https://github.com/trickortweak/flickr-uploader -- didn't check which one is more recent.

It needs OAUTH updating to the new method (check issue trickortweak/flickr-uploader#86) and also changing all the self.urlgen function calls which generates old authentication POST URLs into @sybrenstuvel flickrapi: this to allow the excellent functionality of flickr-uploadr of UPDATE, REPLACE, DELETE to work.

Any help on updating flicrk-uploadr is most welcome.

@rispoli I am using a different project that was built to use the new OAUTH method. See here https://github.com/alfem/synology-flickr-folder-uploader/blob/master/flickr-folder-uploader.py

It seems to work fine outside of every 2-3 days I must reauthenticate with OAUTH with a new access code? Not sure why that is happening.

Maybe a bit off-topic, I'm sorry sybrenstuvel: @rispoli and @bigzdog I've used sybrenstuvel's excellent flickrapi and I've forked flickr-uploadr to improve it.

Version 2.5.10 is out on this link

  • New Authentication for flickr.
  • Use of flickrapi.
  • Multiprocessing to achieve speedy and parallel uploads. Marvellous for 59K photos Library like mine.
  • A bunch of new options
  • Setup instructions for Synology
  • and much more

Do read the README.md

Enjoy! And help out testing! I've applied to a secondary account on flickr.com for testing.
You can do the same!