~mardy/account-plugins/descriptions-1590786

« back to all changes in this revision

Viewing changes to qml/google/Main.qml

  • Committer: Alberto Mardegan
  • Date: 2013-06-07 11:56:25 UTC
  • mto: (113.2.5 qml)
  • mto: This revision was merged to the branch mainline in revision 117.
  • Revision ID: alberto.mardegan@canonical.com-20130607115625-0cvlyuzaoyniy1x6
Add QML plugins for facebook and google

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import Ubuntu.OnlineAccounts.Plugin 1.0
 
2
 
 
3
OAuthMain {
 
4
    creationComponent: OAuth {
 
5
        function completeCreation(reply) {
 
6
            console.log("Access token: " + reply.AccessToken)
 
7
            var http = new XMLHttpRequest()
 
8
            var url = "https://www.googleapis.com/oauth2/v3/userinfo";
 
9
            http.open("POST", url, true);
 
10
            http.setRequestHeader("Authorization", "Bearer " + reply.AccessToken)
 
11
            http.onreadystatechange = function() {
 
12
                if (http.readyState === 4){
 
13
                    if (http.status == 200) {
 
14
                        console.log("ok")
 
15
                        console.log("response text: " + http.responseText)
 
16
                        var response = JSON.parse(http.responseText)
 
17
                        account.updateDisplayName(response.email)
 
18
                        account.synced.connect(finished)
 
19
                        account.sync()
 
20
 
 
21
                    } else {
 
22
                        console.log("error: " + http.status)
 
23
                        cancel()
 
24
                    }
 
25
                }
 
26
            };
 
27
 
 
28
            http.send(null);
 
29
        }
 
30
    }
 
31
}