gpt4 book ai didi

java - 无法连接到 Google Play 服务;获取取消状态代码

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:26 26 4
gpt4 key购买 nike

因此,我正在尝试使用 Google Fit,但出于某种原因,我无法在我的应用程序中连接到 Google Play 服务。我已经完全设置了 OAuth,并在另一个应用程序中对其进行了测试,一切正常。具体查看 GoogleFitRepository,这是我连接到 API 的地方。

我在尝试连接时遇到此错误:

W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.
I/MyApp: Google Play services connection failed. Cause: ConnectionResult{statusCode=CANCELED, resolution=null, message=null}

GitHub 链接:https://github.com/drb56/FitnessExplorer

如有任何帮助,我们将不胜感激。我整天都被困在这个问题上!

编辑:这是相关类的一些代码

public GoogleFitRepository(Activity activity)
{
mClient = new GoogleApiClient.Builder(activity.getApplicationContext())
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.enableAutoManage((FragmentActivity)activity, 0, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i("MyApp", "Google Play services connection failed. Cause: " +
result.toString());
}})
.build();

activityList = new ArrayList<>();
activityDataPointList = new ArrayList<>();
calorieActivitiesToday = new ArrayList<>();
dayActivities = new ArrayList<>();
}

最佳答案

新更新需要 google signin api 与 fit api 一起执行。

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE), new Scope(Scopes.FITNESS_LOCATION_READ))
.build();

googleApiClient = new GoogleApiClient.Builder(activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(connectionCallbacks)
.addOnConnectionFailedListener(failedListener)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.SENSORS_API)
.enableAutoManage(this, 0, this)
.build();

您必须在 console.developers.google.com 上启用 Auth API。请通过 Google Auth API 的服务器端实现。否则上面的代码将无法运行

关于java - 无法连接到 Google Play 服务;获取取消状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com