2

次のコードを使用して、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>`

ありがとう

4

2 に答える 2

1

Googleコンタクト1.XAPIを使用しようとしているようです。これは非推奨になりました。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 に答える