繁体   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)?

我正在开发一个可生成文件的android应用,我需要将这些文件上传到Google驱动器,但仅使用一个特定帐户。 有没有办法做到这一点?

现在,我有了这段代码,可以选择该帐户:

@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();
    }
}

提前致谢

不能。GoogleApiClient使用设备上存在的Google帐户进行连接,因此Drive Android API将只能在这些帐户上获取/创建文件。 根据定义,如果您希望所有客户端都备份到单个Drive帐户,则所有这些客户端都应具有该帐户的凭据,这是不安全的。

听起来您需要一个客户端可以连接到并发布任何数据的服务器端点。 如果您需要预先准备好的解决方案, 查看firebase( https://firebase.google.com/docs/storage/ )提供的存储API。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM