Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

cordova - how implement google drive in ionic app

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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());
                }
            });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...