Friday, March 28, 2014

Google Drive API

Google drive is Google's File storage and synchronisation service. This service allows user to have cloud based file storage, collaborative editing, synchronization. the files can be stored publically and Google search engine picks it up for search indexing.

Google provides a client software for most of the famous platforms so that the files are syncrhonized periodically. the space available to user on cloud storage is distributed among various applications such as gmail, picasa, docs etc.

a note aside, it was interesting to read that Googles famous web app Google Doc was from a 4 man army company called writely which was acquired by Google. Also, the Google spreadsheet also from another acquired firm 2Web Technologies.

Now getting on to the programming aspects of it. Below are few notes after going through the samples and articles inorder to fully utilize the API features.

For enabling the API, had to go to the Google API console and enable the Drive API. Saw another permission for Drive SDK. enabled that too, but this is not really required unless creating web apps that require Google Drive access.

the below are main APIs availalble in this SDK


GTLQueryDrive => This class is a common query class for various Google drive SDK. 
for e.g. inorder to get the list of files already available, below is the code segment 

GTLQueryDrive *queryDrive = [GTLQueryDrive queryForFilesList];

The Query needs to be sent with the GTLServiceDrive classes's executeQuery Method. This method is a block one which returns the GTLServiceTicket and list of files in GTLDriveFileList parameters. Applications can list the files iterating the GTLDriveFileList APIs. 

Inorder to save contents into a drive file in cloud, below is the procedure. 

[GTLUploadParameters uploadParametersWithData:fileContent MIMEType:@"text/plain"];
GTLQueryDrive *query  = [QTLQueryDrive queryFilesInsertWithObject: self.driveFile uploadParameters:uploadParameters];

 [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                                            GTLDriveFile *updatedFile,
                                                            NSError *error) 

This is going to pretty useful feature with the wide variety of APIs available. 

References:

https://developers.google.com/drive/ios/





No comments:

Post a Comment