2016-05-06 19 views
0

オープンソースプロジェクトにGoogle適合APIを統合する際に、ユーザーがGoogleアカウントの資格情報とユーザーの同意プロセスを使用してログインできる場所で作業しています。 Uriのサインに追加のスコープ権限を渡そうとすると、このエラーが発生します。 URLエンコードに問題があるかどうかはわかりません。なぜなら、APIが範囲URLの配列を期待しているからです。 Google fit APIの統合で複数の権限を1つのoauthフローに入れることは可能ですか?複数の許可スコープGoogle適合API統合

最初のURLは正常に動作していますが、他のURLはリダイレクトする代わりにエラーになります。

https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?access_type%3Doffline%26as%3D43045f60390ad399%26approval_prompt%3Dforce%26scope%3Dhttps://www.googleapis.com/auth/fitness.activity.read%26response_type%3Dcode%26redirect_uri%3Dhttps://developers.google.com/oauthplayground%26client_id%3D1086862838918-d6epsnkqrid4tu786geh3nfugpga2ii5.apps.googleusercontent.com%26from_login%3D1&oauth=1&sarp=1&scc=1 


https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?access_type%3Doffline%26as%3D43045f60390ad399%26approval_prompt%3Dforce%26scope%3D%5B%22https://www.googleapis.com/auth/fitness.activity.read%22%2%22https://www.googleapis.com/auth/fitness.activity.write%26response_type%3Dcode%22%5D%26redirect_uri%3Dhttps://developers.google.com/oauthplayground%26client_id%3D1086862838918-d6epsnkqrid4tu786geh3nfugpga2ii5.apps.googleusercontent.com%26from_login%3D1&oauth=1&sarp=1&scc=1 

答えて

1

GoogleのGetting Started on Androidドキュメントを確認しましたか?ここでスコープを追加するための彼らのサンプルコードは次のとおりです。

mClient = new GoogleApiClient.Builder(this) 
.addApi(Fitness.SENSORS_API) 
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) 
.addConnectionCallbacks(this) 
.build() 

あなたが使用する範囲の許可を得るためにaddApi()addScope()を使用して試すことができます。

このチュートリアルでは、Google Fit for Android: Sessions APIから、Google Fit APIの統合に複数の許可範囲を追加することができます。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
ButterKnife.bind(this); 

mGoogleApiClient = new GoogleApiClient.Builder(this) 
.addApi(Fitness.SESSIONS_API) 
.addApi(Fitness.HISTORY_API) 
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) 
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) 
.addConnectionCallbacks(this) 
.enableAutoManage(this, 0, this) 
.build(); 
} 

EDIT:ここ

が彼らのサンプルコードで

はウェブのために私は要求、追加のスコープが必要とされてどこにあなたがOAuth 2.0の

auth2 = gapi.auth2.init({ 
client_id: 'CLIENT_ID.apps.googleusercontent.com', 
cookiepolicy: 'single_host_origin', /** Default value **/ 
scope: 'profile' });    /** Base scope **/ 

経由で追加の権限を要求し使用することができると思います追加するスコープを持つオプションビルダーを構築し、user.grant({scope: [OPTIONS BUILDER]}).then(successFunction, failFunction);

var options = new gapi.auth2.SigninOptionsBuilder(
     {'scope': 'email https://www.googleapis.com/auth/drive'}); 

googleUser = auth2.currentUser.get(); 
googleUser.grant(options).then(
    function(success){ 
     console.log(JSON.stringify({message: "success", value: success})); 
    }, 
    function(fail){ 
     alert(JSON.stringify({message: "fail", value: fail})); 
    }); 

そしてここGoogle FIT web

のスコープの一覧はHTH

+0

私はAndroidプラットフォーム上でそれを試していないでのNode.js、あなたにこれを追加nodejsを持っているChromeの拡張機能を構築していますバックエンド。 nodejs ajaxモジュールを使用していますが、認証フローの後にパーミッションスコープを追加できるメソッドはありません。ここで働いているものがあります。 [link](https://www.npmjs.com/package/ajax-request)。ありがとう –

関連する問題