【问题标题】:Google Drive Api can't connect/authorize to google accountGoogle Drive Api 无法连接/授权到 google 帐户
【发布时间】:2017-01-16 12:58:54
【问题描述】:

我正在尝试构建一个集成了 google drive api 并将驱动器用作它的存储存储的 android 应用程序,但是我从一开始就遇到了问题。 我一直在尝试遵循以下官方指南: https://developers.google.com/drive/android/get-started 以及我找到的另一个指南https://www.numetriclabz.com/integrate-google-drive-in-android-tutorial/,甚至下载了源代码并只是替换了我的 API 密钥,但是使用这两个指南我遇到了完全相同的问题。

每当我尝试测试运行应用程序以查看应用程序是否连接到驱动器时​​,我都会在控制台中获得以下输出:

$ adb shell am start -n "app.googledrive/app.googledrive.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Connected to process 2889 on device emulator-5554
W/System: ClassLoader referenced unknown path: /data/app/app.googledrive-1/lib/x86
I/InstantRun: Instant Run Runtime started. Android package is app.googledrive, real application class is null.

              [ 01-16 12:33:01.211  1561: 1584 D/         ]
              HostConnection::get() New Host Connection established 0x953a3740, tid 1584
W/System: ClassLoader referenced unknown path: /data/app/app.googledrive-1/lib/x86
I/GMPM: App measurement is starting up, version: 8487
I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
E/EGL_emulation: tid 2930: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x94efd500, error=EGL_BAD_MATCH
I/Google Drive Activity: GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{e061739: android.os.BinderProxy@2c1717e}, message=null}

此外,还会弹出 Google 登录以向我添加帐户,这意味着它连接到 Google 服务器,但由于某种原因无法识别帐户/登录。我还尝试重新生成密钥库并将其再次添加到开发人员控制台并使用不受限制的密钥,但是出现了同样的问题。

非常感谢任何有关如何解决此问题的帮助或建议,谢谢。

【问题讨论】:

  • 在设备上试试,可能是模拟器登录有问题
  • 感谢@avinash 的建议。我确实尝试直接在 android 设备上运行它,但是它仍然不允许我选择一个帐户并继续,因为每当我在设备中单击我的帐户时,android studio 中仍然会出现以下消息:
  • 01-17 13:35:13.375 9923-9923/app.googledrive D/AppTracker: App Event: start 01-17 13:35:13.413 9923-9923/app.googledrive I/Google Drive Activity: GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{a77a4d3: android.os.BinderProxy@3009081}, message=null} 01-17 13:35:13.429 9923-9923/app.googledrive D/AppTracker: App Event: stop 01-17 13:35:13.445 9923-9923/app.googledrive D/AbstractTracker: Event success 01-17 13:35:13.463 9923-9923/app.googledrive D/AbstractTracker: Event success
  • 奇怪我使用了来自developers.google.com/drive/android/get-started的样本,但没有问题。是否可以发布您的代码,并确保在控制台上启用 API

标签: android android-studio google-api google-drive-api google-drive-android-api


【解决方案1】:

这不是答案,但它会帮助你。

首先定义您将保存到哪个 Google 帐户。如果用户使用自己的帐户或某个中心化帐户,整个辣酱玉米饼馅就完全不同了。

接下来,您需要决定要使用哪个 API/SDK。假设您希望用户保存到他自己的 Google 帐户,您可以选择使用 REST API(有或没有 Java SDK)或 Android API。 REST API 允许访问所有 Drive 功能,但仅在手机在线并且需要一些争论才能获得授权时才有效。 Google Drive Android API (GDAA) 提供了部分功能,但更易于使用,并且具有允许离线访问的优势。

【讨论】:

  • 感谢@pinoyyid 的回答,在我看来,在这种情况下,我试图为我的应用程序使用错误的 API。我计划为我的应用程序使用一个集中式帐户,该帐户将用于存储和访问 google 驱动器上的 android 手机的数据。我也不担心连接,因为手机也需要在线才能使用其他功能。在这种情况下,我将尝试在 google 上搜索更多关于 REST API 的信息,我猜测凭据需要在应用程序中进行硬编码?
  • 如果您想使用单个集中式帐户,那么是的,凭据需要存储在应用程序中。您可以选择使用凭证为密钥对的服务帐户,或使用凭证为刷新令牌的常规帐户。请注意,您将遇到的大多数示例代码都适用于您的应用将访问用户自己的帐户的用例,因此需要处理身份验证和授权。
  • 我不知道我是不是真的那么笨还是什么,但最近几天我一直在尝试查找官方文档和其他线程,试图找到一些设置示例启动 REST API,然后继续使用服务帐户进行授权,但我似乎无法让这个小而重要的部分正常工作。我知道这可能有点过分要求,但你碰巧没有这两件事的示例代码? (为 android 设备设置驱动 REST API 并使用服务帐户进行身份验证)非常感谢您的帮助 :)!!!
猜你喜欢
  • 1970-01-01
  • 2019-07-27
  • 2015-12-26
  • 1970-01-01
  • 2012-10-26
  • 2019-02-03
  • 2018-07-11
  • 2013-08-21
  • 2017-10-17
相关资源
最近更新 更多