簡體   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