2

我正在使用以下代码获取谷歌联系人姓名和电话号码。授权页面本身无法正常显示,它显示错误为“您请求的页面无效”。:(请帮我解决这个问题...

`

<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>`

谢谢

4

2 回答 2

1

您似乎正在尝试使用 Google Contacts 1.X API。这已被弃用。查看Google 3.X API 的 JavaScript 示例,看看是否有帮助。

于 2012-08-03T03:35:32.213 回答
0

你可以试试这个例子

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);
    });
}

不要忘记添加<script src="https://apis.google.com/js/client.js"></script>到您的 html 文件中。祝你好运!

于 2017-01-10T10:21:51.630 回答