相关疑难解决方法(0)

Google Drive 同意屏幕卡住

我正在尝试在 Google Drive 上备份我的 Android 应用程序的应用程序数据。因此,我请求使用 google_sign_in 包访问https://www.googleapis.com/auth/drive.appdatahttps://www.googleapis.com/auth/drive.file范围。

我在 Google 开发者控制台上创建了一个项目,启用了 Drive API,并将范围添加到 OAuth 同意屏幕,并添加了包含包名称和调试密钥的 SHA-1 的 OAuth 客户端 ID。

如果我不请求任何范围,该应用程序工作正常,但请求“驱动”范围会使同意屏幕卡住并且永远加载。我有什么遗漏的吗?

以下是应用程序的代码和卡住的屏幕加载 同意屏幕加载

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

Future<GoogleSignInAccount> handleSignIn() async {
  try {
    return await GoogleSignIn(
      scopes: [
        'https://www.googleapis.com/auth/drive.appdata',
        'https://www.googleapis.com/auth/drive.file',
      ],
    ).signIn();
  } catch (error) {
    print(error);
    return null;
  }
}

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: …
Run Code Online (Sandbox Code Playgroud)

android dart google-drive-api google-signin flutter

6
推荐指数
1
解决办法
1499
查看次数

使用 Google Drive API 的 Android 应用程序在选择帐户后卡住。为什么?

我试图了解如何将 Google Drive API 集成到我的 Android 应用程序中(使用 Android Studio)。我已经尝试了在这里找到的示例应用程序(https://github.com/googleworkspace/android-samples/tree/master/drive/deprecation),但是在 Google API 控制台配置之后,当我选择一个时,我的应用程序陷入无限循环帐户。为什么?哪里有问题?我也尝试过这个(https://youtu.be/5bSEIQYJzKs)教程,但我有同样的问题。这是我的 build.gradle 具体行:

implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev136-1.25.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation ('com.google.api-client:google-api-client-android:1.26.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
Run Code Online (Sandbox Code Playgroud)

这是我使用的版本

compileSdkVersion 30
buildToolsVersion "30.0.3"
Run Code Online (Sandbox Code Playgroud)

问题出在这段代码行中,并且仅在我使用“.requestScopes(new Scope(DriveScopes.DRIVE_FILE))”时才会出现:如果我不使用 .requestScopes(new Scope(DriveScopes.DRIVE_FILE))”,则代码可以正常工作。并且用户确实已登录

GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                .requestEmail()
                .build();
GoogleSignInClient client= GoogleSignIn.getClient(this,signInOptions);
Intent i= client.getSignInIntent();
startActivityForResult(i,400);
Run Code Online (Sandbox Code Playgroud)

(看起来该活动永远不会返回任何值)。如果没有“.requestScopes(new Scope(DriveScopes.DRIVE_FILE))”,则身份验证请求会成功。这是我的 Google 控制台配置: 客户端 ID (抱歉,也许它会显示为链接,但 stackOverflow 告诉我不能放置 img),“.../auth/drive.file”是我请求的授权向用户显示的 google 同意窗口。我不知道这是否重要,但我使用真实的手机而不是 Android Studio 模拟器来测试我的应用程序。

android google-drive-api android-studio

3
推荐指数
1
解决办法
2792
查看次数