【问题标题】:Google Contacts API errorGoogle 通讯录 API 错误
【发布时间】:2012-08-02 06:29:27
【问题描述】:

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

`

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

谢谢

【问题讨论】:

    标签: javascript google-api google-contacts-api


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你可以试试这个例子

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

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

      【讨论】:

        猜你喜欢
        • 2011-10-23
        • 1970-01-01
        • 1970-01-01
        • 2014-11-30
        • 2011-09-02
        • 2016-07-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多