Android Google Drive Rest API:跳过同意屏幕(硬编码帐户) [英] Android Google Drive Rest API: skip consent screen (hardcoded account)

查看:131
本文介绍了Android Google Drive Rest API:跳过同意屏幕(硬编码帐户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Google云端硬盘同步一些媒体文件(视频/图像),并在我的android应用中显示它们.

I was trying to use Google Drive to sync some media files (video/images) and show them in my android app.

我已经设法使其一切正常,但是根据文档(或至少从第一读)来看,必须始终有一个同意屏幕 >用户在选择了自己的Google帐户后,同意该应用从其驱动器获取数据的情况.

I've managed to make it all work fine but according to the docs (or at least from a first read) it looks like there must always be a consent screen where the user, after choosing his google account, agrees with the app getting data from his drive.

重点是,我想以编程方式对此帐户进行硬编码",因为我们的应用始终会从同一帐户获取媒体.

The point is that I'd like to 'hardcode' an account that programatically agrees to that since our app is always going to take the media from the same account.

有可能吗?

PD:不要建议其他任何存储服务,云端硬盘是客户的要求.

PD: Don't suggest any other storage service, Drive is a client's requirement.

推荐答案

最后,我设法使其完全起作用:

Finally I've managed to make it work altogether:

  1. 从您的Google开发者控制台中创建一个服务帐户凭据.
  2. 下载json格式的凭据.
  3. 将文件复制到资产/res/原始文件.
  4. 将您的json重命名为没有奇怪字符的内容(例如: driveserviceprivatekey.json ).
  5. 列表项

  1. Create a service account credential from your google developers console.
  2. Download your credential in json format.
  3. Copy the file into assets/res/raw.
  4. Rename your json into something without weirds chars (Ex: driveserviceprivatekey.json).
  5. List item

    InputStream privateJsonStream = dashboardActivity.getResources().openRawResource(R.raw.driveserviceprivatekey);
    GoogleCredential serviceCredential = GoogleCredential.fromStream(privateJsonStream).createScoped(Arrays.asList(SCOPES));

  • 现在,您可以按以下方式使用驱动器服务:

  • Now you can use your drive service as follows:

                HttpTransport transport = AndroidHttp.newCompatibleTransport();
                JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
                this.mService = new com.google.api.services.drive.Drive.Builder(
            transport, jsonFactory, null)
            .setHttpRequestInitializer(credential)
            .build();
    

  • 这篇关于Android Google Drive Rest API:跳过同意屏幕(硬编码帐户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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