何時間もこれと格闘してきましたが、ドキュメントはひどいようです。基本的に、PortableContactsAPIまたは本格的なContactsAPIのいずれかを使用して、OAuth2認証済みユーザーの連絡先への読み取りアクセスを取得しようとしています。Googleは最近OAuth2の許可を開始しました。
最初にユーザーにスコープ「https://www.google.com/m8/feeds」で認証させることで、ContactsAPIを介してユーザーの連絡先にアクセスできます。次に、jQueryを使用して最初の25件の連絡先を取得できます(表示されているコードはCoffeeScriptです) 。
$.ajax
url: "https://www.google.com/m8/feeds/contacts/default/full"
dataType: 'jsonp'
data: { access_token: token, alt: 'json-in-script' }
success: (data, status) ->
console.log "The returned data", data
それは機能し、JSONデータを取得します。しかし、ほとんど信じられないことに、Googleが提供する唯一の連絡先の注文は(私が知る限り)「最終変更」(真剣にwtf?)です。「トップフレンズ」や「最も人気のある」のようなものが必要です。
これは、たまたまGoogle PortableContacts APIでできることです(そうです!)。もちろん、私は仕事への成功した要求を得ることができないようです。
まず、このリンクをクリックして、ユーザーにポータブル連絡先APIで認証してもらいます(スコープに注意してください: "https://www-opensocial.googleusercontent.com/api/people")
<a href="https://accounts.google.com/o/oauth2/authclient_id=457681297736.apps.googleusercontent.com&response_type=token&redirect_uri=http://localhost:3000/team&scope=https://www-opensocial.googleusercontent.com/api/people">Import Google Contacts</a>
これは正常に機能し、アクセストークンが返されます。
次に、ポータブル連絡先APIにajaxリクエストを送信しようとします
$.ajax
url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all"
dataType: 'jsonp'
data: { access_token: token, alt: 'json-in-script' }
success: (data, status) ->
console.log "The returned data", data
しかし、それは403エラーを返します
403 (The currently logged in user and/or the gadget requesting data, does not have access to people data.
私が間違っていることについて何か考えはありますか?
付録このバグレポートはGoogleOAuth2フォーラムで
見つかりました。このバグレポートでは、PortableContactsAPIを使用するときに認証ヘッダーを設定する必要があるとアドバイスされていました。だから私はこのようにそれを試しました:
$.ajax
url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all"
dataType: 'jsonp'
data: { access_token: token, alt: 'json-in-script' }
beforeSend: (xhr) ->
xhr.setRequestHeader "Authorization", "OAuth #{token}"
data: { access_token: token }
success: (data, status) ->
console.log "The returned data", data
しかし、それは私に同じ403エラーをもたらします:
403 (The currently logged in user and/or the gadget requesting data, does not have access to people data