TL;博士; 如果使用 Google+ 登录,GoogleFit Api 客户端无法连接
所以...我在同时使用 GoogleFit 和 Google+ api 时遇到了问题。我正在使用 Google+ 登录用户并使用 GoogleFit 来检索健身。
除了 Google+,我还有其他几个登录选项,例如 Facebook 和 Twitter。我的问题是,如果用户使用 Google+ 登录,则用户将无法再连接到 Google Fit 客户端。基本上,当按下连接到 GoogleFit 的按钮时,什么也没有发生。如果用户使用 Facebook 或 Twitter 进行身份验证,GoogleFit 客户端可以正常连接......
以下是此活动的一些相关代码:
Google+ 客户端:
private GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
}
Google Fit 客户端,只要用户按下按钮将 GoogleFit 链接到应用程序,就会调用此方法:
public void buildFitnessClient(Button b) {
// Create the Google API Client
fitConnectButton = b;
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mClient.connect();
}
生命周期的东西:
@Override
public void onConnected(Bundle bundle) {
mSignInClicked = false;
if(mGoogleServices != null) {
Plus.PeopleApi.loadVisible(mGoogleServices, null).setResultCallback(this);
userData = getProfileInformation();
}
if (hasWearDevice) mClient.connect();
}
@Override
protected void onStart() {
super.onStart();
// Connect to G+ api
if(mGoogleServices != null) mGoogleServices.connect();
// Connect to the Fitness API
if (hasWearDevice) mClient.connect();
}
@Override
public void onStop() {
super.onStop();
if(mGoogleServices != null) {
if(mGoogleServices.isConnected()) mGoogleServices.disconnect();
}
if(hasWearDevice) {
if(mClient.isConnected()) mClient.disconnect();
}
}
有什么建议么?