【问题标题】:Is there any working tutorial for using google-api's with flutter for android是否有任何使用 google-api 和 flutter for android 的工作教程
【发布时间】:2023-02-20 07:16:33
【问题描述】:

我正在尝试将 google drive API 与 flutter 一起使用,在 android 真实设备上进行测试。我关注了一些 youtube 视频和媒体博客,但无法正常工作。如果您知道任何教程,请在此处发布。

我目前正在使用这些包 googleapis: ^7.0.0, googleapis_auth: ^1.3.0。

我遇到了一个关于 redirect_uri 的错误

这是代码的一部分

import 'dart:io';

import 'package:google_drive_upload/helpers/constants.dart';
import 'package:googleapis/drive/v3.dart' as gdrive;
import 'package:googleapis_auth/auth_io.dart';
import 'package:url_launcher/url_launcher.dart';

class DriveService {
  List<String> _scopes = [gdrive.DriveApi.driveScope];

  getHttpClient() async {
    return await clientViaUserConsent(ClientId(clientId), _scopes, prompt);
  }

  prompt(String url) {
    launch(url);
  }

  upload(File file) async {
    var client = await getHttpClient();
    var drive = gdrive.DriveApi(client);
    var res = await drive.files.create(
      gdrive.File(),
      uploadMedia: gdrive.Media(file.openRead(), file.lengthSync()),
    );

    print('Response here ${res.toJson()}');
  }
}

我在 android 的 Oauth 凭据中找不到 Oauth 客户端中的 redirect_uri(尽管它可用于 Web 客户端)。

请帮我解决这个问题,因为 2 天以来一直被困在这里:(

编辑 1尝试使用具有完全随机应用程序名称的新应用程序,因此 android 域不会发生冲突,结果仍然相同。

【问题讨论】:

  • 看起来您正在使用为网络应用程序而不是 Android 应用程序设计的代码。要么找到 android 代码,要么在谷歌开发者控制台上创建一个网络应用程序凭据。 stackoverflow.com/q/65784077/1841839
  • 嘿,我尝试了那个答案中给出的步骤,我在不同的端口号上遇到了同样的错误。顺便说一句,我的android buid域是com.example.google_drive_demo_app,它与它有什么关系吗?因为我关注的 youtube 视频有他自己的域名

标签: android flutter google-api


【解决方案1】:

你需要使用谷歌签名包,Sa 来使用谷歌自定义重定向链接enter link description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多