如何将客户端ID添加到Java的Google Drive客户端API [英] How to add client id to Google Drive Client API for Java

查看:68
本文介绍了如何将客户端ID添加到Java的Google Drive客户端API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在Android应用中使用Google Drive REST API.(我无法使用 Android版Google Drive API ,因为该应用需要共享文件,以及GDAA不支持的其他一些内容.)我有两点要坚持.

I'm just getting started with using the Google Drive REST API in an Android app. (I can't use the Google Drive API for Android because the app needs to share files, and perhaps a few other things, that GDAA doesn't support.) I'm stuck on a couple of points.

第一个与OAuth2.0凭据有关.我查看了 Android快速入门示例,它运行良好.我在Google开发人员控制台上设置了一个项目,并生成了OAuth2.0客户端ID和密码,还下载了JSON凭证文件.但是,快速入门示例未显示如何将其中的任何一个插入应用程序.我在文档中发现的唯一相关的东西是 Java快速入门示例使用了此方法,但未与之集成Android的帐户管理器,似乎不适用于Android应用程序.)当我运行快速启动应用程序的Android版本时,开发人员控制台上没有显示任何活动,这向我表明该应用程序以某种匿名方式运行.模式.据我了解,这将限制该应用程序的每日交易额度非常低.

The first has to do with OAuth2.0 credentials. I went through the Android quick start example and it works fine. I set up a project on my Google developer console and generated an OAuth2.0 client ID and secret and also downloaded the JSON credentials file. However, the quick start example doesn't show how to plug any of this into the app. The only thing I found in the docs that seems relevant is GoogleClientSecrets, but I don't see anything about how to use that in an Android app. (The Java quick start example uses this, but it's not integrated with Android's account manager and doesn't seem right for an Android app.) When I run the Android version of the quick start app, no activity shows up on my developer console, which suggests to me that the app is running in some sort of anonymous mode. As I understand it, that would limit the app to a very low daily quota of transactions.

第二,我注意到GDAA和REST API for JavaScript都有不错的文件选择器API.我在Java/Android API中找不到任何类似的东西.

Second, I noticed that the GDAA and the REST API for JavaScript both have nice file picker APIs. I couldn't find anything similar in the Java/Android API.

这是我的具体问题:

  • 如何在Android Java应用程序的REST API中使用开发者控制台中应用程序的OAuth2.0凭据?我觉得我只是缺少明显的东西.
  • 是否存在适用于Android的Google Rest API的文件选择器API?

推荐答案

当我执行快速入门示例(一个痛苦的过程,因为没有源代码)逐步浏览该库后,我找到了答案.原来,您需要在清单中指定客户端ID.具体来说,您需要在< application> 标记下添加以下内容:

After stepping through the library as I executed the Quickstart example (a painful process, as there is no source code), I discovered the answer. It turns out that you need to specify the client ID in the manifest. Specifically, you needs the following under the <application> tag:

<meta-data
    android:name="com.google.app.id"
    android:value="app ID from your API console"/>

一旦此条目位于清单中,则当应用程序使用Google Drive REST API与Google的服务器进行交互时,该交易将作为流量正确记录在应用程序的控制台中.没有此条目,该应用程序似乎可以在我的测试中正常工作,但未记录任何流量.我似乎从旧的Google I/O视频中回想起这种匿名"应用程序仍然可以运行,但是使用配额非常低(每天大约10或100个查询).

Once this entry is in the manifest, then when the app uses the Google Drive REST API to interact with Google's servers, the transaction is correctly logged as traffic in your app's console. Without this entry, the app seemed to work in my testing, but no traffic was logged. I seem to recall (from an old Google I/O video) that such "anonymous" apps still work, but have a very low usage quota (something like 10 or 100 queries/day).

对于那些好奇的人,我在 play-services-basement-10.2中找到的类 com.google.android.gms.common.internal.zzz 中找到了此键.0 库.

For those who are curious, I found this key in the class com.google.android.gms.common.internal.zzz, found in the play-services-basement-10.2.0 library.

这篇关于如何将客户端ID添加到Java的Google Drive客户端API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆