如何在离子应用中实施谷歌驱动器 [英] how implement google drive in ionic app

查看:137
本文介绍了如何在离子应用中实施谷歌驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将我的离子应用程序连接到谷歌驱动器,显示所有文件,也许上传,下载,删除,编辑。所以我试试这个
https://github.com/Raza-Dar/ionic-google-drive2



错误:
无法加载资源:服务器响应的状态为404(未找到) https://apis.google.com/ / scs / apps-static / / js / k = oz.gapi.en.RArmLpCIYB0.O / m ... 1 / ed = 1 / am = QQ / rs = AGLTcCOEiG2RgKkKDvOG7y5PZ-fMFMsJXQ / t = zcms / cb = gapi.loaded_01

未捕获的TypeError:无法调用未定义的方法'load'

无法找到InAppBrowser插件



和这
http://blog.ionic.io/oauth- ionic-ngcordova / 1
在控制台上没有错误...但验证后返回主页面



和这
http://excellencenodejsblog.com/cordova-ionic-google-oauth-login-for-your-mobile-app/
与此我得到的用户的信息,但不是文件

任何建议?请给我一些工作示例启动代码
谢谢

解决方案

您需要使用Google本地化您的cordova应用程序以便使用API​​。首先,按照官方的Google指南为每个平台(iOS和Android),如果您还没有,为您的应用程序创建所需的凭据。然后尝试下面链接中的插件:



科尔多瓦谷歌驱动器插件



我为个人移动项目创建了这个插件。这个插件支持上传,下载和文件列表。



要检索您的Android应用程序创建/上传的文件列表,您可以在Java端尝试以下操作:

  private void fileList(){
Query query = new Query.Builder()。addFilter(Filters.and(
Filters.eq(SearchableField.MIME_TYPE, application / octet-stream),
Filters.eq(SearchableField.TRASHED,false)))。build();

Drive.DriveApi.query(mGoogleApiClient,query)
.setResultCallback(new ResultCallback< DriveApi.MetadataBufferResult>(){
@Override
public void onResult(DriveApi .MetadataBufferResult结果){
if(!result.getStatus()。isSuccess()){
mCallbackContext.sendPluginResult(New PluginResult(PluginResult.Status.ERROR,failed to retrieve file list));
return;
}
MetadataBuffer flist = result.getMetadataBuffer();
Log.i(TAG,flist.get(0).getClass()。getName());
JSONArray response = new JSONArray();
for(Metadata file:flist
){
try {
response.put(new JSONObject()。put( name,file.getTitle())。put(created,file.getCreatedDate()。toS tring())。put(id,file.getDriveId()。toString()));
} catch(JSONException ex){ex.getMessage();}
}
JSONObject flistJSON = new JSONObject();
尝试{
flistJSON.put(flist,response);
} catch(JSONException ex){}
mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,flistJSON));
flist.release();
//Log.i(TAG,flist.toString());
}
});
}


i need to connect my ionic app to google drive, show all the files, and maybe upload, download,delete, edit.So I try this https://github.com/Raza-Dar/ionic-google-drive2

errors: Failed to load resource: the server responded with a status of 404 (Not Found) https://apis.google.com//scs/apps-static//js/k=oz.gapi.en.RArmLpCIYB0.O/m…1/ed=1/am=QQ/rs=AGLTcCOEiG2RgKkKDvOG7y5PZ-fMFMsJXQ/t=zcms/cb=gapi.loaded_01

Uncaught TypeError: Cannot call method 'load' of undefined

Could not find InAppBrowser plugin

and this http://blog.ionic.io/oauth-ionic-ngcordova/1 no errors on console...but after authentication return to the main page

and this http://excellencenodejsblog.com/cordova-ionic-google-oauth-login-for-your-mobile-app/ with this i get the info of the users but not the file in drive

any suggestion?Please i need some working example starter code Thank you

解决方案

You need to authenticate natively your cordova application with Google in order to make use of the APIs. Firstly follow the official Google guides for each platform (iOS and Android) if you haven't already, to create the required credentials for your application. Then try the plugin on the link below:

Cordova google drive plugin

I created this plugin for a personal mobile project. This plugin supports upload,download and list of files.

To retrieve a list of files created/uploaded by your application for Android you can try this on Java side:

private void fileList() {
    Query query = new Query.Builder().addFilter(Filters.and(
            Filters.eq(SearchableField.MIME_TYPE, "application/octet-stream"),
            Filters.eq(SearchableField.TRASHED, false))).build();

    Drive.DriveApi.query(mGoogleApiClient, query)
            .setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
                @Override
                public void onResult(DriveApi.MetadataBufferResult result) {
                    if (!result.getStatus().isSuccess()) {
                        mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR,"failed to retrieve file list"));
                        return;
                    }
                    MetadataBuffer flist = result.getMetadataBuffer();
                    Log.i(TAG,flist.get(0).getClass().getName());
                    JSONArray response = new JSONArray();
                    for (Metadata file: flist
                         ) {
                        try {
                            response.put(new JSONObject().put("name", file.getTitle()).put("created", file.getCreatedDate().toString()).put("id", file.getDriveId().toString()));
                        }catch (JSONException ex){ex.getMessage();}
                    }
                    JSONObject flistJSON = new JSONObject();
                    try{
                        flistJSON.put("flist", response);
                    } catch (JSONException ex){}
                    mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,flistJSON));
                    flist.release();
                    //Log.i(TAG,flist.toString());
                }
            });
}

这篇关于如何在离子应用中实施谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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