~danielholm/+junk/lastfm-online-account

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
from gi.repository import Accounts, Signon
 
# ...get an AccountService...
 
# Get the authentication informations
auth_data = account_service.get_auth_data()
identity = auth_data.get_credentials_id()
session_data = auth_data.get_parameters()
 
# Create an authentication session
auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
 
# Define the callback function
def login_cb(self, session, reply, error, user_data):
    if error:
        print("Got authentication error:", error.message)
        return
    print("login finished; reply: %s", (reply,))
 
    # The contents of "reply" depend on the method/mechanism used.
    # Here we suppose we were using OAuth 2.0
    if "AccessToken" in reply:
        access_token = reply["AccessToken"]
 
# Start the authentication. Note that you must have a GLib main loop
# running in order for the callback to be called.
auth_session.process(session_data,
            auth_data.get_mechanism(),
            login_cb, None)