【问题标题】:Google Drive Api authentication in Android appAndroid 应用中的 Google Drive Api 身份验证
【发布时间】:2017-07-27 00:11:53
【问题描述】:

我在我的 Android 应用程序中使用谷歌驱动器我的应用程序自动拍照并上传到驱动器,但问题是身份验证它要求在我第一次打开应用程序时选择谷歌帐户,我可以以编程方式提供我的凭据和完成身份验证,这样我就可以避免使用 UI 进行选择和身份验证的这一步。

【问题讨论】:

    标签: android google-drive-android-api


    【解决方案1】:

    您可以参考这个link。这可以通过https://developers.google.com/oauthplayground 的 Oauth2 Playground 来完成。

    步骤:-

    1. 创建 Google 帐户(例如 my.drive.app@gmail.com)
    2. 使用 API 控制台注册 mydriveapp (https://console.developers.google.com/apis/credentials/oauthclient?project=mydriveapp 或者只是https://console.developers.google.com/apis/)
    3. 创建一组新的凭据(NB OAuth Client ID not Service Account Key 然后从 选择)
    4. https://developers.google.com/oauthplayground 包含为有效的重定向 URI
    5. 记下客户端 ID(网络应用)和客户端密码
    6. 以 my.drive.app@gmail.com 身份登录
    7. 去 Oauth2 游乐场
    8. 在设置(齿轮图标)中,设置 * Oauth 流程:服务器 * 访问类型:离线 * 使用您自己的 OAuth 凭据:TICK * 客户端 ID 和客户密码:从第 5 步开始
    9. 点击 Step 1 并选择 Drive API https://www.googleapis.com/auth/drive(话虽如此,这 该技术也适用于列出的任何 Google API)
    10. 单击授权 API。系统将提示您选择您的 Google 帐户并确认访问权限
    11. 点击步骤 2 和“兑换令牌的授权码”
    12. 复制返回的刷新令牌并将其粘贴到您的应用、源代码或某种形式的存储中,您的应用可以从中检索 它。

    您也可以使用Service Account。但是,它会为该应用创建一个伪 Drive 帐户,而不是允许该应用访问您的常规 Drive 帐户。检查this

    【讨论】:

    • 我已经完成了上述步骤,并且我有客户端 ID、客户端密码、刷新令牌和访问令牌,但是在我使用以下调用 ui 来选择一个帐户 mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } mGoogleApiClient.connect();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 2015-08-17
    相关资源
    最近更新 更多