npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-jc-googledrive

v1.1.0

Published

Cordova Google Drive Plugin

Downloads

8

Readme

Cordova Google Drive plugin

This plugin allows you to authenticate and access user's Google Drive account, using the new Rest API as recommended (Read more here).

Installation

Prerequistics

$ git clone https://github.com/JcDenton86/cordova-plugin-jc-googledrive.git

  1. Open the Library page and enable the Google Drive API for a project (create a new project if you don't have one)

  2. Open the Credentials page in the API Console and follow the steps below in the given order:

    • Click Create credentials > OAuth client ID.
    • Select Android or iOS.
    • In the Package name field (or Bundle ID for iOS), enter your app's package name.
    • On Android: Paste the SHA1 fingerprint into the form where requested (on iOS skip this)
      • read more under "Get an Android certificate and register your application", here
    • Click Create.

Install with cordova-cli

If you are using cordova-cli, install with:

cordova plugin add cordova-plugin-jc-googledrive --variable IOS_REVERSED_CLIENT_ID=com.googleusercontent.apps.YOUR_CLIENT_ID --variable IOS_CLIENT_ID=YOUR_CLIENT_ID.apps.googleusercontent.com

The IOS_REVERSED_CLIENT_ID is the "iOS URL Scheme" on the Google Developer's Console. The variables are only for iOS platform. You can omit them if you are developing for Android.

Read only for iOS

This plugin requires some additions to make it work on iOS properly:

Firstly, make sure you have installed cocoapods because it is needed to install some dependencies using pod.

Secondly and after succesfull installation of the dependencies:

Open AppDelegate.m file and add 1) these header files along with the rest on the top and 2) the code block before the @end command:

#import "AppAuth.h"
#import "GoogleDrive.h"

//....

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<NSString *, id> *)options {
    
    if ([_currentAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
        _currentAuthorizationFlow = nil;
        return YES;
    }
    
    return NO;
}
//...
@end

Open AppDelegate.h file and paste this code before the @end command :

@protocol OIDAuthorizationFlowSession;

@interface AppDelegate : CDVAppDelegate {}
@property(nonatomic, strong, nullable) id<OIDAuthorizationFlowSession> currentAuthorizationFlow;

That's it! You are ready to use the plugin.

important: in case you use xCode to build or run the app on simulator or device you should open the .xcworkspace file instead of .xcodeproj

Usage (Javascript)

If you are using jQuery, AngularJS, WinJS or any Promise/A library, promise style is supported.

downloadFile

The downloadFile function follows the proper authentication procedure. If the user allows the app to access Google Drive, this method will download the file requested (fileId) and will save it to the path you indicated (toLocalDest).

var toLocalDest = "path/to/local/destination/file.ext";
var fileid = "GoogleDrive_FileID";
window.plugins.gdrive.downloadFile(toLocalDest, fileid,
   function (response) {
       //simple response message with the status
   },
   function (error){
     console.log(error);
   }
);

uploadFile

The uploadFile function will upload a file selected from a given local path (fpath) to the root folder of user's drive. You can upload files to the app's folder or root folder based on the boolean value of the second parameter the method takes. If you set the value to true, it will upload files under app's folder. The difference between the two folders is the access permission of the file uploaded. Files under app folder, are no visible to the user and only the application has access to them. These files are uploaded under backup section with the rest of the applications. This is useful for files with sensitive data, such as databases etc. where the user must not have access or when your app support some kind of backup action.

var fpath = "path/to/local/file.ext";
window.plugins.gdrive.uploadFile(fpath,
   function (response) {
      //simple response message with the status
   },
   function (error){
     console.log(error);
   }
);

deleteFile

The deleteFile function removes from root directory previously uploaded or created file. The file is moved to the user's drive trash.

var fileid = "GoogleDrive_FileID";
window.plugins.gdrive.deleteFile(fileid,
   function(res){
   console.log(res);
   },
   function(err){
   console.log(err);
   }
);

fileList

The fileList function shows a list of files, created or uploaded by the application and have not been trashed. Selecting a file, you can have access to the drive fileId and in the created date. You can list files from app's folder or root folder based on the boolean value of the first parameter the method takes. If you set the value to true, it will fetch files under app's folder.

window.plugins.gdrive.fileList(
   function(res){
     //the files are under res.flist;
   console.log(res);
   },
   function(err){
   console.log(err);
   }
);

requestSync (currently only on Android)

The requestSync function forces a synchronization with the Drive server. This might be useful in case fileList returns an empty array of files.

var returnFiles = true;
window.plugins.gdrive.requestSync(returnFiles,
   function(res){
   console.log(res);
   },
   function(err){
   console.log(err);
   }
);

The success callback will return a JSON object. The attribute flist will hold an array with the files found on user's application folder on Drive.

Contribution

You are more than welcome to provide features and help with the development. Leaving issues or requests is accepted but my free time in not enough which means that I will try to support this plugin as long as my free time allows.

## Credits

This plugin has been created by Jeries Besharat Other people that have contributed and commited features and improvements: