我正在尝试为大学项目设置 Google Fit API,但是我刚刚注意到在选择 Google 登录后出现错误RESULT_CANCELED
。
我已经阅读了其他一些论坛页面并尝试了一些解决方案:
- 将密钥库更改为发布模式,而不是调试
- 改变依赖
- 更改密钥库签名配置
没有什么对我有用!我不知道我做错了什么,所以请向我提问,我很乐意提供帮助。我知道我正在使用已弃用的 API 函数,但是我找不到任何我了解如何实现的最新信息。
研究了堆栈溢出答案:
Google Fit O Auth failed with RESULT_CANCELED without shown permission page
Google Oauth 2.0 RESULT_CANCELED while using Google Fit api
建造者
mApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.GOALS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_OAUTH) {
authInProgress = false;
if (resultCode == RESULT_OK) {
if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
mApiClient.connect();
}
} else if (resultCode == RESULT_CANCELED) {
Log.e("GoogleFit", "RESULT_CANCELED");
}
} else {
Log.e("GoogleFit", "requestCode NOT request_oauth");
}
}
配置
release {
storeFile file("C:\\Program Files\\Java\\jdk1.8.0_144\\bin")
storePassword "pw"
keyAlias "release"
keyPassword "pw"
}