授权谷歌云端硬盘Android API [英] Authorizing the Google Drive Android API

查看:138
本文介绍了授权谷歌云端硬盘Android API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了谷歌云端硬盘Android API 访问谷歌开我的数据(不网页API)。什么是疯狂,当我使用这个访问,我可以访问的磁盘(只是一个文件夹和一些文件)只有很小的一部分。我试图用例如code,仍然,结果是一样的。任何想法可能是错误的?

在授权

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstance);mGoogleApiClient =新GoogleApiClient.Builder(本)
        .addApi(Drive.API)
        .addScope(Drive.SCOPE_FILE)
        .addConnectionCallbacks(本)
        .addOnConnectionFailedListener(本)
        。建立();
}@覆盖
保护无效调用onStart(){
super.onStart();
mGoogleApiClient.connect();
}

阅读内容

  @覆盖
公共无效onConnected(捆绑connectionHint){
    super.onConnected(connectionHint);
    查询查询=新Query.Builder()
            .addFilter(Filters.or(
                    Filters.eq(SearchableField.MIME_TYPE,text / html的),
                    Filters.eq(SearchableField.MIME_TYPE,text / plain的)))
            。建立();
    Drive.DriveApi.query(getGoogleApiClient(),查询).setResultCallback(metadataCallback);
}  ResultCallback< MetadataBufferResult> childrenRetrievedCallback =新
        ResultCallback< MetadataBufferResult>(){
    @覆盖
    公共无效onResult(MetadataBufferResult结果){
        如果(!result.getStatus()。isSuccess()){
            showMessage(,而检索文件问题);
            返回;
        }
        mResultsAdapter.clear();
        mResultsAdapter.append(result.getMetadataBuffer());
        showMessage(成功上市的文件。);
    }
};


解决方案

由于API文档:

注:谷歌云端硬盘Android API目前仅支持 drive.file drive.appfolder 的授权范围。如果您的应用需要额外的权限或驱动器的Andr​​oid API中的功能尚不可用,则必须使用谷歌API的Java客户端。

我想你需要驱动器授权,但是这还没有准备好为Android API。

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.");
    }
};

解决方案

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.

这篇关于授权谷歌云端硬盘Android API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆