简体   繁体   English

如何强制Android应用程序仅使用某个帐户来使用Google Drive API(GDAA)?

[英]How can I force an android app to use only a certain account to use google drive api (GDAA)?

I am developing an android app that generates files and I need to upload these files to google drive but using only an specific account. 我正在开发一个可生成文件的android应用,我需要将这些文件上传到Google驱动器,但仅使用一个特定帐户。 Is there a way to do this? 有没有办法做到这一点?

For now I have this code that allows me to choose the account : 现在,我有了这段代码,可以选择该帐户:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

}
 @Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}

Thanks in advance 提前致谢

No. The GoogleApiClient uses the google accounts present on the device to connect and thus the Drive Android API will only be able to fetch/create files on those account. 不能。GoogleApiClient使用设备上存在的Google帐户进行连接,因此Drive Android API将只能在这些帐户上获取/创建文件。 By definition if you want all the clients to backup to a single Drive account, all those client should have the credentials for that account which is not safe. 根据定义,如果您希望所有客户端都备份到单个Drive帐户,则所有这些客户端都应具有该帐户的凭据,这是不安全的。

It sounds like you need a single server endpoint where your clients can connect to and post any data. 听起来您需要一个客户端可以连接到并发布任何数据的服务器端点。 Look into storage APIs provided by firebase ( https://firebase.google.com/docs/storage/ ) if you want a pre-cooked solution. 如果您需要预先准备好的解决方案, 查看firebase( https://firebase.google.com/docs/storage/ )提供的存储API。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Google Drive API 扫描 Android Studio 应用程序中的文档? - How can I use Google Drive API to scan a document in an Android Studio app? Google Drive Android API(GDAA)getResourceId()返回null(计时问题) - Google Drive Android API (GDAA) getResourceId() returning null (timing issue) 使用GDAA(适用于Android的Google Drive Api)创建/编辑/检索数据库文件 - Create / Edit / Retrieve DB file with GDAA (Google Drive Api for Android) 新的Google Drive Android API(GDAA)创建的文件未显示 - Files created by the NEW Google Drive Android API (GDAA) not showing up 如何在Android中使用Google Drive API? - How to use Google Drive api in Android? [Android]使用Google云端硬盘SDK,以及如何登录其他帐户 - [Android]Use the Google Drive Sdk, how to sign in to another account GDAA(Google Drive Android API):使用fileId从AppDataFolder下载文件 - GDAA(Google Drive Android API): download file from AppDataFolder by using fileId 如何让我的Android应用使用“服务帐户”访问共享的Google日历? - How can I make my Android app use a “Service Account” to access a shared Google Calendar? 如何使用Google Drive API密钥从android应用程序访问驱动器内容? - How do I use the Google drive API key to access drive content from android application? 如何在具有Google帐户的Android中使用AccountManager? - How can I use AccountManager in Android with Google Account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM