cordova-plugin-jc-googledrive
cordova-plugin-jc-googledrive copied to clipboard
How to Use this plugin In IONIC 2
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
I wanna include this plugin in my Ionic 2 app too!! Please help.
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.
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 I also had the same problem. End up I put wrong certificate sha1 hash in google api console.
@tomcatmwi I am also getting the error message "user cancelled connection" Have you resolved the problem. Could please share me the steps of resolving.
@JcDenton86 Could you please help me in resolving the error message "user cancelled connection".
thanks in advance.
I solved the problem by making sure of these things
-
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
-
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)
-
Make sure to use the correct package name in the Google API Console.