【问题标题】:How should I set up OAuth consent screen without Android app verification?我应该如何在没有 Android 应用验证的情况下设置 OAuth 同意屏幕?
【发布时间】:2020-11-04 10:07:53
【问题描述】:

我正在开发一个使用 Google Fit API 的 Android 应用程序。我在Google Developer Console 上启用了它,它提供了客户端 ID 和 API 密钥。 我应该如何设置 OAuth 屏幕?

我的应用程序使用 Sessions API 来记录数据,使用 History API 来查看以前存储的数据。目前,我可以记录可在 Google Fit 应用中查看的活动数据,但在使用 History API 时出现此错误

com.google.android.gms.common.api.ApiException: 5000: Application needs OAuth consent from the user

我想检查 API 的功能只是为了演示,所以应用程序不需要验证。我应该如何设置同意屏幕或征求用户同意?
我是否需要对活动阅读和写作等敏感范围进行验证?

【问题讨论】:

    标签: android google-api google-fit google-fit-sdk


    【解决方案1】:
    1. 检查您是否请求具有相关读/写权限的正确范围: https://developers.google.com/fit/android/api-client-example
    val fitnessOptions = FitnessOptions.builder()
        .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
        .addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
        .build()
    
    1. 检查您没有尝试从您无权访问的范围中读取:

    即在响应中更改下面的数据类型DataType.AGGREGATE_STEP_COUNT_DELTA

    private fun accessGoogleFit() {
        val end = LocalDateTime.now()
        val start = end.minusYears(1)
        val endSeconds = end.atZone(ZoneId.systemDefault()).toEpochSecond()
        val startSeconds = start.atZone(ZoneId.systemDefault()).toEpochSecond()
    
        val readRequest = DataReadRequest.Builder()
            .aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA)
            .setTimeRange(startSeconds, endSeconds, TimeUnit.SECONDS)
            .bucketByTime(1, TimeUnit.DAYS)
            .build()
        val account = GoogleSignIn.getAccountForExtension(this, fitnessOptions)
        Fitness.getHistoryClient(this, account)
            .readData(readRequest)
            .addOnSuccessListener({ response ->
                // Use response data here
                Log.i(TAG, "OnSuccess()")
            })
            .addOnFailureListener({ e -> Log.d(TAG, "OnFailure()", e) })
    }
    

    【讨论】:

    • 感谢您的解决方案
    猜你喜欢
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多