简体   繁体   English

授权Google Drive Android API

[英]Authorizing the Google Drive Android API

I tried to access my data in Google Drive over Google Drive Android API (not Web API). 我试图通过Google Drive Android API (而非Web API)访问Google Drive中的数据。 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.");
    }
};

As API documentation: 作为API文档:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. 注意:Google Drive Android API当前仅支持drive.filedrive.appfolder授权范围。 If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client. 如果您的应用程序需要其他权限或云端硬盘Android API中尚不可用的功能,则必须使用Google API Java Client。

I think you need drive authorization, but this is not ready for Android API. 我认为您需要drive授权,但这还不能用于Android API。

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

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