1

私はここでグーグルの連絡先を取得するために取り組んできました。ユーザーの個人情報を取得しましたが、ユーザーの連絡先を取得できません。次のエラーが発生します:401(認証が必要です)

https://www.google.com/m8/feeds/contacts/xyz@gmail.com/full?oauthtoken=[object%20Object]&callback=jQuery162xxxxxxxxxx_13xxxxxxxxxx2&_=13xxxxxx。

$.ajax({
                    url: "https://www.google.com/m8/feeds/contacts/default/full",
                    dataType: "jsonp",
                    headers: "GData-Version: 3.0",
                    data:{accessToken: authResult },
                    success: function (data) {
                        console.log("json"+JSON.stringify(data));
                    }
});
4

3 に答える 3

1

私はこれに答えました:

// OAuth configurations   
    var config = {
      'client_id': 'xxxxxx.apps.googleusercontent.com',
      'scope': 'https://www.google.com/m8/feeds/contacts/default/full'          
    };

gapi.auth.authorize(config, function(data) {
      // login complete - now get token
      var token = gapi.auth.getToken();
      token.alt = 'json';
      // retrieve contacts
      jQuery.ajax({
        url: 'https://www.google.com/m8/feeds/contacts/default/full/?max-results=999999',
        dataType: 'jsonp',
        data: token,
        success: function(data) { successGmail(data); }
      });
    });

そこ : JSONP リクエストの HTTP ヘッダーを変更する

于 2014-05-27T09:27:41.013 に答える
1

最初のコード ブロック (URL を含む) で、クエリ パラメーター name を指定しますoauthtoken。2 番目のコード ブロックでは、パラメータ値 を指定しますaccessToken

このパラメータ値は、実際には である必要がありますaccess_token。こちらをご覧ください: https://developers.google.com/accounts/docs/OAuth2UserAgent#callinganapi

于 2012-08-07T18:08:51.660 に答える
0

ヘッダーにトークンを "Authorization: Bearer " + authResult として書き込もうとすることができるので、この例ではコードは次のようになります。

$.ajax({
       url: "https://www.google.com/m8/feeds/contacts/default/full",
       type: "GET",
       dataType: "jsonp",
       headers: {
                   "Authorization": "Bearer " + authResult,
                   "GData-Version": "3.0"
                },
       success: function (data) {
            console.log("json"+JSON.stringify(data));
       }
});

JQuery Docsは、ajaxヘッダーパラメータについて次のように述べています。

リクエストと共に送信する追加のヘッダー キー/値ペアのマップ[...]

そのため、元の文字列をマップに変更しました。タイプはデフォルトで GET であるため、オプションです。

お役に立てれば

于 2012-12-04T18:27:39.567 に答える