多权限范围 google 适合 api 集成
multiple permisions scope google fit api integration
我正在将 Google fit API 集成到一个开源项目中,我正在开发一个允许用户使用 Google 帐户凭据登录并通过用户同意流程的项目。当我尝试在登录 Uri 上传递额外的范围权限时出现此错误。我不确定我的 URL 编码是否有问题,因为我确定 API 需要一个范围 url 数组。是否可以在 Google fit API 集成中将多个权限放在一个 oauth 流程中?
第一个 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
您是否查看了 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()
来获取要使用的 Scope 的权限。
从本教程开始: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();
}
编辑:
对于网络,我认为您可以使用通过 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}));
});
将此添加给您 node.js 然后这是 Google FIT web
的范围列表
HTH
我正在将 Google fit API 集成到一个开源项目中,我正在开发一个允许用户使用 Google 帐户凭据登录并通过用户同意流程的项目。当我尝试在登录 Uri 上传递额外的范围权限时出现此错误。我不确定我的 URL 编码是否有问题,因为我确定 API 需要一个范围 url 数组。是否可以在 Google fit API 集成中将多个权限放在一个 oauth 流程中?
第一个 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
您是否查看了 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()
来获取要使用的 Scope 的权限。
从本教程开始: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();
}
编辑:
对于网络,我认为您可以使用通过 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}));
});
将此添加给您 node.js 然后这是 Google FIT web
的范围列表HTH