1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var oauth = ChromeExOAuth.initBackgroundPage({
6 'request_url' : 'https://www.google.com/accounts/OAuthGetRequestToken',
7 'authorize_url' : 'https://www.google.com/accounts/OAuthAuthorizeToken',
8 'access_url' : 'https://www.google.com/accounts/OAuthGetAccessToken',
9 'consumer_key' : 'anonymous',
10 'consumer_secret' : 'anonymous',
11 'scope' : 'http://www.google.com/m8/feeds/',
12 'app_name' : 'Sample - OAuth Contacts'
18 if (oauth.hasToken()) {
19 chrome.browserAction.setIcon({ 'path' : 'img/icon-19-on.png'});
21 chrome.browserAction.setIcon({ 'path' : 'img/icon-19-off.png'});
25 function onContacts(text, xhr) {
27 var data = JSON.parse(text);
28 for (var i = 0, entry; entry = data.feed.entry[i]; i++) {
30 'name' : entry['title']['$t'],
31 'id' : entry['id']['$t'],
35 if (entry['gd$email']) {
36 var emails = entry['gd$email'];
37 for (var j = 0, email; email = emails[j]; j++) {
38 contact['emails'].push(email['address']);
42 if (!contact['name']) {
43 contact['name'] = contact['emails'][0] || "<Unknown>";
45 contacts.push(contact);
48 chrome.tabs.create({ 'url' : 'contacts.html'});
51 function getContacts() {
52 oauth.authorize(function() {
53 console.log("on authorize");
55 var url = "http://www.google.com/m8/feeds/contacts/default/full";
56 oauth.sendSignedRequest(url, onContacts, {
71 chrome.browserAction.onClicked.addListener(getContacts);