[英]Access Google Drive API using GoogleAuthUtil token
TL/DR: How to access google services from a service running in the background? TL / DR:如何从后台运行的服务访问Google服务?
There are 2 versions of connecting to Drive API 有2个版本的Drive API连接
Credential
object 告诉如何使用Credential
对象的java GoogleApiClient
机器人可以告诉你如何使用GoogleApiClient
None of them telling how to use it in the background service, eg saving user data every now and then. 他们没有一个告诉如何在后台服务中使用它,例如,不时地保存用户数据。
Also in another android guide I found use of GoogleAuthUtil
which can help me to obtain token which I can use later on but I can not find a single example on how to use Drive API through token! 同样在另一个Android指南中,我发现使用GoogleAuthUtil
可以帮助我获取令牌,以后可以使用它,但是我找不到有关如何通过令牌使用Drive API的单个示例!
About sample code of save file to Google Drive, you can refer this link( https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/drive/sample/demo/EditContentsActivity.java).But , this sample is using AsyncTask instead of Service as a background process. 关于将文件保存到Google云端硬盘的示例代码,您可以参考以下链接( https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/ drive / sample / demo / EditContentsActivity.java)。但是 ,此示例使用AsyncTask代替Service作为后台进程。 If really like to implement that process in Service, you can do it by copy-paste EditContentsAsyncTask's code to Service. 如果真的想在Service中实现该过程,则可以通过将EditContentsAsyncTask的代码复制粘贴到Service来实现。 Reason not to use service in the sample code is because Service still runs in your application's main thread by default, About Service and AsyncTask, you can refer this link "Should you use a service or a thread?"( http://developer.android.com/guide/components/services.html ). 在示例代码中不使用服务的原因是,由于默认情况下Service仍在应用程序的主线程中运行,即About Service和AsyncTask,因此您可以引用此链接“您应该使用服务还是线程?”( http://developer.com。 android.com/guide/components/services.html )。
And the different between using GoogleAuthUtil and GoogleApiClient,you can refer this link( what is the right way to sign in google: GoogleAuthUtil or GoogleApiClient ). 与使用GoogleAuthUtil和GoogleApiClient的不同之处在于,您可以引用此链接( 登录google的正确方法是:GoogleAuthUtil或GoogleApiClient )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.