Android Backup Service

Dear Scott. Again, thanks for your excellent job. I will continue awaiting it.

Thanks a lot again.

Regards

Wait no more
http://marketplace.coronalabs.com/plugin/google-drive

Dear Scott,

Fantastic !!. Thanks so much a lot for your excellent job.

I’m going to use it following your well done guides.

Thanks again. Great job.

Dear Scott, its fantastic. I have tested your example and followed your detailed info and works fine.

Only I don’t know how to copy files to an specific folder at Google Drive. I will use this extension for a backup of a user data file (in zip format) for my app. DropBox allow to write only to the App directory. With this extension I have access to all the user root files. I only need to save restore backup file from/to an App folder, or, create an specific folder to save the App data and not disturb or write to the root directory to avoid the user can delete accidentally the backup file. 

It is possible to create a folder and copy the file to that folder?

I don’t find the way to only have access to Apps folder (if it exist in Google Drive).

Any suggestion?

Thanks for your excellent job dear. You did it perfect !!!

I need to make some change to the plugin hold on

This has been added seehttps://scottrules44.com/plugin#GoogleDriveIt is at the bottem, please sign out first Add drive.onlyAppAccess(true). This require a re sign in and this should be declared before calling drive.login

I have not tested yet, I will fix it if it needs it but it should work

Dear Scott, thanks again for your excellent work.

I’m testing with it. I have add

drive.onlyAppAccess(true)

before drive.init and ok

but, now, when try to upload a file, I have the error:

“{\n “error”: {\n  “errors”: [\n   {\n    “domain”: “global”,\n    “reason”: “insufficientFilePermissions”,\n    “message”: “The user does not have sufficient permissions for this file.”\n   }\n  ],\n  “code”: 403,\n  “message”: “The user does not have sufficient permissions for this file.”\n }\n}\n”

I think it is the credentials. I have no way to configure the corrects credentials in google drive.

I used this:

local fileName = “arrow”

drive.request(“https://www.googleapis.com/upload/drive/v3/files/”, “POST”, function ( e )

print(json.encode(e.response))

end, {uploadType= “multipart”}, {parent = “appDataFolder”, name = fileName}, fileName…".png", system.ResourceDirectory, “image/png”, fileName )

but the answer is:

“{\n “error”: {\n  “errors”: [\n   {\n    “domain”: “global”,\n    “reason”: “insufficientFilePermissions”,\n    “message”: “The user does not have sufficient permissions for this file.”\n   }\n  ],\n  “code”: 403,\n  “message”: “The user does not have sufficient permissions for this file.”\n }\n}\n”

if I disable the new option you prepared ( --drive.onlyAppAccess(true) )

then create a file but no way to create at the appDataFolder.

Any idea?

Thanks again.

 

I am looking at this right now

I think I got this working, I am going to have to submit some updates. But the way this believe it or not this is the same a google play cloud save

You may have to do two requests.

I am making some new apis to make this easier

This has been added in 2.0

https://forums.coronalabs.com/topic/65160-google-drive/

Please note I have not tried uploading zip files to app data folder

Dear Scott,

Sorry my delay in answer.

I’m testing with the drive.createFileInAppData , and drive.listFilesInAppData but always the corona simulator give me the error:

Attempt to call field ‘createFileInAppData’ (a nil value)

and

Attempt to call field ‘listFilesInAppData’ (a nil value)

I’m using your example code. But appear not work for the application folder.

I’m missing any?

Thanks again in advance,

Is

drive.onlyAppAccess(true)

Called before login?

Thanks so much dear Scott.

I going to test with it.

Best regards,

Dear Scott,

Thanks again for your quick answer and sorry for my delay.

Dear, yes. The problem is that 

drive.onlyAppAccess(true)

give an error.

Corona say: 'Attempt to call field ‘onlyAppAccess’ (a nil value)

The same error I have for others:

drive.createFileInAppData

To include the plugging I do:

local drive = require(“plugin.googleDrive”) – (not this due this don’t work --> “drive.googleDrive”)

I’m testing your example. The normal works fine and perfect, but all for the AppData fails. Appear to not recognize createFileInAppData.

Perhaps configuration?

Thanks again for your excellent work.

This code works for me

local drive = require("plugin.googleDrive") local json = require("json") local canMakeRequest = false drive.onlyAppAccess(true) drive.init("insert your stuff here") -- update this local signOutButton local requestButton local loginButton = display.newGroup() loginButton.box = display.newRoundedRect( loginButton,0, 0, 100, 50, 10 ) loginButton.myText = display.newText( loginButton, "Login", 0, 0 , native.systemFont , 15 ) loginButton.myText:setFillColor( 0 ) loginButton.x, loginButton.y = display.contentCenterX, display.contentCenterY loginButton.alpha = 1 loginButton.box:addEventListener( "tap", function ( event ) local function driveLis( e ) print(e.error) if (not e.error) then canMakeRequest = true signOutButton.alpha = 1 requestButton.alpha = 1 loginButton.alpha = 0 end end drive.login(driveLis) end) requestButton = display.newGroup() requestButton.box = display.newRoundedRect( requestButton,0, 0, 100, 50, 10 ) requestButton.myText = display.newText( requestButton, "Request", 0, 0 , native.systemFont , 15 ) requestButton.myText:setFillColor( 0 ) requestButton.x, requestButton.y = display.contentCenterX, display.contentCenterY-100 requestButton.alpha = 0 requestButton.box:addEventListener( "tap", function ( e ) --upload image --[[local fileName = "arrow" drive.request("https://www.googleapis.com/upload/drive/v3/files/", "POST", function ( e ) print(e.response) end, {uploadType= "multipart"}, {name = fileName, parents ={"appDataFolder"}}, fileName..".png", system.ResourceDirectory, "image/png", fileName ) --]] --delete file --[[local fileId = "0B5swSg-cH4L6cjdTWU94RTNDR0E" drive.request("https://www.googleapis.com/upload/drive/v3/files/"..fileId, "DELETE", function ( e ) print(e.response) end, {fileId= fileId} )]]-- --update file --[[local fileId = "0B5swSg-cH4L6cjdTWU94RTNDR0E" local fileName = "arrow" drive.request("https://www.googleapis.com/upload/drive/v3/files/"..fileId, "PATCH", function ( e ) print(e.response) end, {fileId= fileId, uploadType= "multipart"}, {name = fileName}, fileName..".png", system.ResourceDirectory, "image/png", fileName )]]-- --list file(s) --[[drive.request("https://www.googleapis.com/drive/v3/files/", "GET", function ( e ) print(e.response) end, {orderBy ="modifiedTime"} )]]-- --download file --[[local fileId = "" drive.download(fileId, nil, function ( e ) print(e.response) end ,"arrow.png", system.TemporaryDirectory) --]] ------------- ----app folder requests --upload to app folder ----[[local fileName = "config.json" print(fileName) drive.request("https://www.googleapis.com/upload/drive/v3/files/", "POST", function ( e ) print(e.response) end, {uploadType= "multipart"}, {name = fileName, mimeType = "application/json", parents={"appDataFolder"}},"config.json", system.ResourceDirectory, "application/json", fileName ) --]] --list files --[[drive.request("https://www.googleapis.com/drive/v3/files/", "GET", function ( e ) print(e.response) end, {spaces= "appDataFolder"} )]]-- --download file --[[local fileId = "1a26sFl6YLCj0hbHX\_3CpspysgrF71VpTp5QAn27VGro" drive.download(fileId, nil,function ( e ) print(json.encode(e.response)) end ,"config.json", system.TemporaryDirectory)]]-- end ) signOutButton = display.newGroup() signOutButton.box = display.newRoundedRect( signOutButton,0, 0, 100, 50, 10 ) signOutButton.myText = display.newText( signOutButton, "Sign Out", 0, 0 , native.systemFont , 15 ) signOutButton.myText:setFillColor( 0 ) signOutButton.x, signOutButton.y = display.contentCenterX, display.contentCenterY+100 signOutButton.alpha = 0 signOutButton.box:addEventListener( "tap", function ( e ) drive.signOut(function ( event ) if not event.error then signOutButton.alpha = 0 requestButton.alpha = 0 loginButton.alpha = 1 canMakeRequest = false end end) end )

Ps updated sample to fix that issue with the require

Dear Scott,

I have been testing and work perfect now. The AppFolder is hidden to the user in google drive and secure. And works fine.

Only 1 question: I’m trying to create a folder to upload the files to this new folder. Google explain that need to change the mimeType to

mimeType = “application/vnd.google-apps.folder”

Any way to do it?

If I try the following:

local fileName = “arrow”

drive.request(“https://www.googleapis.com/upload/drive/v3/files/”, “POST”, function ( e )

   print(e.response)

end, {uploadType= “multipart”}, {name = fileName, mimeType = “application/vnd.google-apps.folder”}, fileName …".png", system.ResourceDirectory, “image/png”, fileName )

The answer is:

nil

{

 “kind”: “drive#file”,

 “id”: “0B-0lZ-JxWcf1bWRQRzFsSWxSZ2s”,

 “name”: “arrow”,

 “mimeType”: “application/octet-stream”

}

Any way to change the mimeType?

or

Any way to create a folder and to upload files to that folder?

Dear, thanks again for your excellent job,

Dear, also the name for the file when using the app data folder always go Untitled…

Using this:

local fileName = “config.json”

print(fileName)

drive.request(“https://www.googleapis.com/upload/drive/v3/files/”, “POST”, function ( e )

print(e.response)

end, {uploadType= “multipart”}, {name = fileName, mimeType = “application/json”, parents={“appDataFolder”}},“config.json”, system.ResourceDirectory, “application/json”, fileName )

Cause this result:

{

 “kind”: “drive#file”,

 “id”: “1gi4QMQ12wZkI1wMcBic1OgM8cHLpZhqk37-2ZLhVn-KO”,

 “name”: “Untitled”,

 “mimeType”: “application/octet-stream”

}

And when list the files with:

drive.request(“https://www.googleapis.com/drive/v3/files/”, “GET”, function ( e )

print(e.response)

end, {spaces= “appDataFolder”} )

Answer all my files in appdatafolder that all named in the same way Untitled

{

 “kind”: “drive#fileList”,

 “files”: [

  {

   “kind”: “drive#file”,

   “id”: “1gi4QMQ12wZkI1wMcBic1OgM8cHLpZhqk37-2ZLhVn-KO”,

   “name”: “Untitled”,

   “mimeType”: “application/octet-stream”

  },

  {

   “kind”: “drive#file”,

   “id”: “11uoK3859IMBFeYtRp4SgixXrOe7klttXXudpbwfX0_6X”,

   “name”: “Untitled”,

   “mimeType”: “application/octet-stream”

  }

 ]

}

Using the user space (not appdatafolder) works well and keep the correct name, but not the mime type.

Using the app data folder lost the name and all names go to ‘Untitled’. Also I think lost the mime type due always is “application/octet-strem”

Let me know if I can help you in any way with testings.

Thanks again dear,