cordova-plugin-jc-googledrive icon indicating copy to clipboard operation
cordova-plugin-jc-googledrive copied to clipboard

How to Use this plugin In IONIC 2

Open arpitdadheech opened this issue 8 years ago • 7 comments

Hello All

I am working in IONIC 2 chat based application and I want to download google drive files in my specified folder.

I used this code gdrive.downloadFile(toLocalDest, fileid, function (response) { alert("Done"+response); }, function (error){ alert("error"+error); } ); and declared on top :- declare var gdrive: any;

I tried using this it gives me this error

main.js:22 ORIGINAL STACKTRACE: e.handleError @ main.js:22 main.js:22 Error: Uncaught (in promise): ReferenceError: gdrive is not defined ReferenceError: gdrive is not defined at main.js:14 at Object.callbackFromNative (cordova.js:295) at processMessage (cordova.js:1119) at processMessages (cordova.js:1142) at t.invoke (polyfills.js:3) at Object.onInvoke (main.js:5) at t.invoke (polyfills.js:3) at e.run (polyfills.js:3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at s (polyfills.js:3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (main.js:5) at t.invokeTask (polyfills.js:3) at e.runTask (polyfills.js:3) at i (polyfills.js:3) at <anonymous>

Please can someone help me fixing this Issue Thanks

arpitdadheech avatar Jun 19 '17 07:06 arpitdadheech

I wanna include this plugin in my Ionic 2 app too!! Please help.

kanak-infoObjects avatar Jun 19 '17 08:06 kanak-infoObjects

It should work like this:

    let GoogleDrive = (<any>window).plugins.gdrive;

    GoogleDrive.requestSync(
      true,
      res => {
        console.log(res.flist);
      }, err => {
        alert(`Error: ${err.message}`);
      }
    );

Tested in the latest version of Ionic and it works.

stefanbc avatar Oct 10 '17 11:10 stefanbc

It still doesn't work for me.

requestSync() brings up the modal to choose a Google account, but it returns with the error message "user cancelled connection". I used stefanbc's snippet btw.

upload() doesn't even respond. This is why I am trying to do:

        (<any> window).plugins.gdrive.uploadFile(
            filename,
            success => console.log('File "' + path + '" has been uploaded.'),
            error => console.log('Error uploading "' + path + '": ', error));

tomcatmwi avatar Nov 22 '17 00:11 tomcatmwi

@tomcatmwi I also had the same problem. End up I put wrong certificate sha1 hash in google api console.

sainalshah avatar Dec 05 '17 12:12 sainalshah

@tomcatmwi I am also getting the error message "user cancelled connection" Have you resolved the problem. Could please share me the steps of resolving.

jayadhoni avatar Jan 08 '18 17:01 jayadhoni

@JcDenton86 Could you please help me in resolving the error message "user cancelled connection".

thanks in advance.

jayadhoni avatar Jan 08 '18 17:01 jayadhoni

I solved the problem by making sure of these things

  1. The App must be build & Signed with the same key which given in the Google API Console. (important) if you don't sign the apk it will give "user cancelled connection" ERROR

  2. if you are using the file Upload method make sure you add a boolean value after the file path argument ( there is a light mistake in the readme. there are 4 argument instead of 3. (important)

  3. Make sure to use the correct package name in the Google API Console.

SouravDas25 avatar May 30 '18 14:05 SouravDas25