Authorizing the Google Drive Android API

 ̄綄美尐妖づ 提交于 2019-12-11 03:06:58

问题


I tried to access my data in Google Drive over Google Drive Android API (not Web API). What is crazy, that when I use this access, I can access only small part of disk (just a one folder and a few files). I tried to use example code and still, result is same. Any idea what could be wrong?

Authorizing

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstance);

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

@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

Reading content

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    Query query = new Query.Builder()
            .addFilter(Filters.or(
                    Filters.eq(SearchableField.MIME_TYPE, "text/html"),
                    Filters.eq(SearchableField.MIME_TYPE, "text/plain")))
            .build();
    Drive.DriveApi.query(getGoogleApiClient(), query).setResultCallback(metadataCallback);
}

  ResultCallback<MetadataBufferResult> childrenRetrievedCallback = new
        ResultCallback<MetadataBufferResult>() {
    @Override
    public void onResult(MetadataBufferResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Problem while retrieving files");
            return;
        }
        mResultsAdapter.clear();
        mResultsAdapter.append(result.getMetadataBuffer());
        showMessage("Successfully listed files.");
    }
};

回答1:


As API documentation:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.

I think you need drive authorization, but this is not ready for Android API.



来源:https://stackoverflow.com/questions/27714031/authorizing-the-google-drive-android-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!