简体   繁体   English

使用GoogleAuthUtil令牌访问Google Drive API

[英]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连接

  • java which tells how to use Credential object 告诉如何使用Credential对象的java
  • android which tells you how to use 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.

相关问题 在Android中通过GoogleAuthUtil从Google Drive API获取访问令牌 - Get Access Token From Google Drive API by GoogleAuthUtil in Android 访问Google API - GoogleAccountCredential.usingOAuth2与GoogleAuthUtil.getToken() - Access to Google API - GoogleAccountCredential.usingOAuth2 vs GoogleAuthUtil.getToken() 使用Google Play服务进行访问时Google Drive API的配额是多少? - Google Drive API quotas when access using Google Play services? 提取并存储Google Drive Android API的access_token和refresh_token - Fetch and store access_token and refresh_token for google drive android api 使用Google Drive REST API v3访问Google Drive共享链接 - Access google drive shared links using Google Drive REST API v3 Android Google Drive Api令牌错误 - Android Google Drive Api token error 带有访问令牌的 Android Google Drive API v2 downloadUrl 停止工作 - Android Google Drive API v2 downloadUrl with access token stopped working 如何使用谷歌 javascript 库(gapi)和访问令牌将 .json 文件上传到谷歌驱动器? - How to upload .json file to google drive, using google javascript library(gapi) and access token? 使用 Drive API 将图像上传到 Google Drive - Uploading an Image to Google Drive Using Drive API 如何使用通过GoogleAuthUtil类获得的令牌来获取用户信息? - How to use token obtained using GoogleAuthUtil class to get user information?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM