File: oauth_test_3-oob.py

package info (click to toggle)
python-flickrapi 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: python: 2,145; makefile: 147; sh: 10
file content (43 lines) | stat: -rwxr-xr-x 1,259 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python

from xml.etree import ElementTree as ET
import six
import logging
import webbrowser
logging.basicConfig(level=logging.INFO)

from flickrapi import FlickrAPI


class keys:
    apikey = u'a233c66549c9fb5e40a68c1ae156b370'
    apisecret = u'03fbb3ea705fe096'

print('Creating FlickrAPI object')

flickr = FlickrAPI(keys.apikey, keys.apisecret)

# ------------------------------------------------------------------------------
print('Step 1: authenticate')

if not flickr.token_valid(perms='read'):
    # Get a request token
    flickr.get_request_token(oauth_callback='oob')

    # Open a browser at the authentication URL. Do this however
    # you want, as long as the user visits that URL.
    authorize_url = flickr.auth_url(perms='read')
    webbrowser.open_new_tab(authorize_url)

    # Get the verifier code from the user. Do this however you
    # want, as long as the user gives the application the code.
    verifier = six.text_type(six.input('Verifier code: '))

    # Trade the request token for an access token
    flickr.get_access_token(verifier)

# ------------------------------------------------------------------------------
print('Step 2: use Flickr')
resp = flickr.photos.getInfo(photo_id='7658567128')

ET.dump(resp)