Priya N R
Priya N R

Reputation: 21

Google Contacts API error

I'm using the following code to get google contacts name and phone number. Authorization page itself is not coming properly it shows error as "The page you requested is invalid". :( pls help me to solve this...

`

<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
<script type="text/javascript">
  google.load("gdata", "1.x");

  var contactsService;
  function setupContactsService()
  {
  contactsService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0');
  }
  function logMeIn() {
      var scope = 'https://www.google.com/m8/feeds';
      var token = google.accounts.user.login(scope);
      }
  function initFunc() {
      setupContactsService();
      logMeIn();
      getMyContacts();
      }
  function checkLoggedIn(){
      scope = "https://www.google.com/m8/feeds";
      var token = google.accounts.user.checkLogin(scope);

      if(token != "")
      return true;
      else
      return false;
      }
  function getMyContacts() {
      var contactsFeedUri = 'https://www.google.com/m8/feeds/contacts/default/full';

      var query = new google.gdata.contacts.ContactQuery(contactsFeedUri);

      //We load all results by default//
      query.setMaxResults(10);

      contactsService.getContactFeed(query, handleContactsFeed, ContactsServiceInitError);
      }
//Gets the contacts feed passed as parameter//
  var handleContactsFeed = function(result) {

  //All contact entries//
  entries = result.feed.entry;
  for (var i = 0; i < entries.length; i++) {
      var contactEntry = entries[i];
      var telNumbers = contactEntry.getPhoneNumbers();
      var title = contactEntry.getTitle().getText();
      }
}
</script> 
<body>
<input type="submit" value="Login to Google" id="glogin"  onclick="initFunc();">
</body>`

Thanks

Upvotes: 2

Views: 1517

Answers (2)

Vinit Singh
Vinit Singh

Reputation: 53

You can try this example

var config = {
  'client_id': 'Client ID',
  'scope': 'https://www.google.com/m8/feeds'
};

inviteContacts = function() {
   gapi.auth.authorize($scope.config, function() {
       fetch(gapi.auth.getToken());
   });
}

function fetch(token) {
    $.get("https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json", function(response) {
         console.log(response);
         //console.log(response.data.feed.entry);
    });
}

Don't forget to add <script src="https://apis.google.com/js/client.js"></script> into your html file. Good Luck!

Upvotes: 0

Mark S.
Mark S.

Reputation: 4019

It looks like you are trying to use the Google Contacts 1.X API. That's been deprecated. Look at the JavaScript examples for the Google 3.X API and see if that helps.

Upvotes: 1

Related Questions