【问题标题】:Google Drive service account for my android app我的 android 应用程序的 Google Drive 服务帐户
【发布时间】:2017-01-02 11:06:59
【问题描述】:
我想使用谷歌驱动器直接从我的 Andriod 应用程序上传和下载文件,无需任何用户交互。我已经按照驱动器 api 的谷歌快速启动页面,它工作正常,但我希望应用程序直接自我验证,而不要求用户以任何方式选择帐户。我可以输入用户名并在代码期间直接传递。
有服务帐户之类的选项
当我用谷歌搜索这个但没有教程时
还有其他关于 php 和 ruby 的教程,但它们在浏览器上,我希望它与我的应用程序集成。因此,只要我打开我的应用程序,它就应该从谷歌驱动器中获取文件,而无需任何用户
任何有关安卓应用的帮助或教程链接都会有所帮助
【问题讨论】:
标签:
android
google-drive-api
service-accounts
【解决方案1】:
您可以按照this repository 中的服务帐户示例进行操作。
这是一个 sn-p,它显示了如何构建服务帐户凭据。
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
...
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json"))
.createScoped(Collections.singleton(PlusScopes.PLUS_ME));
// Set up global Plus instance.
plus = new Plus.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(APPLICATION_NAME).build();