Work with Google Drive

Kiese

Member
Licensed User
Longtime User
Thanks for the tip @Erel, it might be, so. I am using 3.81. I do get the warning "was created with a newer version of B4A". Most of the time it still works so I ignore it but that might be causing it. Guess I'll update and see how it plays out !:)
 

davfla

Member
Licensed User
Longtime User
Hi all,

I published the source code now because I've not enough time to further development this project. Maybe anyone can optimize the lib for a better usage.

David
 

incendio

Well-Known Member
Licensed User
Longtime User
Hi Davfla,

Thank you for lib. I have log in into google developer console, how to get access key and secret key?
 

rafaelmotaquintana

Active Member
Licensed User
I got the ClientID and secret code, using option 'other', because android option won't give me a secret code.
Connection is successful, but I can't create a folder, I have this in the log

Asking for authorization from user.
Authorization granted by user.
No Access token
Send a request for a new Access token
New Token was created
Token is not correct. Try to refresh.
Error Message : Forbidden
Refresh Token
Create Folder
Forbidden
Refresh token done

What I'm doing wrong?
 

rafaelmotaquintana

Active Member
Licensed User
I got the ClientID and secret code, using option 'other', because android option won't give me a secret code.
Connection is successful, but I can't create a folder, I have this in the log

Asking for authorization from user.
Authorization granted by user.
No Access token
Send a request for a new Access token
New Token was created
Token is not correct. Try to refresh.
Error Message : Forbidden
Refresh Token
Create Folder
Forbidden
Refresh token done

What I'm doing wrong?
SOLVED
Had to enable the drive api in google page.
Now my problem is that it only works in release mode, in debug always gives me this:

An error has ocurred in sub:
java.lang.RuntimeException:
Object should first be initialized (activity).
Did you forget to call
Activity.LoadLayout?

b4A version is 5.80
 

rafaelmotaquintana

Active Member
Licensed User
Hello. I am testing in and cheap tablet. It has no google play nor google drive installed.
The command

B4X:
 GoogleDrive.Initialize(Me, "Drive", clientId, clientSecret)

does not throw any error
so after the command

GoogleDrive.ConnectToDrive

I get this message and the program cancels

An error has occurred in sub:
java.lang.RuntimeException: Object should first be initialized (Activity).
Did you forget to call Activity LoadLayout?
Continue?

My question is, How do I know if the device is capable of use this library (the same program runs fine in another device).
 

Descartex

Well-Known Member
Licensed User
Longtime User
Hi, I'm trying to compile the sample with my credentials but it raises an error
B4X:
Compiling generated Java code.    Error
Cannot find: C:\Program Files\Anywhere Software\Basic4android\libraries\webviewxtended.jar
I'm using B4A V6.00 and WebViewExtras Library is 1.42.

Thanks in advance.
 

Descartex

Well-Known Member
Licensed User
Longtime User
Yes, libGoogleDrive.jar is there
 

Descartex

Well-Known Member
Licensed User
Longtime User
Hi all, can someone provide a step by step on howto obtain client I'd and secret I'd to use this library?, I'm trying, but with no success on Google console. Thanks a lot.
Go to Credentials-> Create -> Oauth ID
Then select Other, input a name for the credential such as "Google Drive Sample App" or something else and click on Create, it raises the ClientId and SecretID.
 

Descartex

Well-Known Member
Licensed User
Longtime User

asales

Expert
Licensed User
Longtime User
I tred this code to retrived the list of files in Google Drive, but don't works:
B4X:
Log(clsDrive.ShowTheFileList)
 

nhz

Member
Licensed User
Longtime User
Hi Davfla,

Thank you for lib. I can upload the files in the root directory of google drive, but can not upload files in sub directories.
I am using the field DriveFolder
clsDrive.UploadFile ("xxxxxxx", "xxxxxxx", "xxxxxx", "drivedir", "")

Maurizio

I am having that problem too. The files cannot be uploaded into sub folders. This way, I cannot share the entire content to the public.
 

Mikonios

Active Member
Licensed User
Longtime User
Hi Davfla.
Thank you for sharing your time and your efforts.
Are there any "Activity Events/clsDrive.DeleteFile" to delete a file on the remote Google Drive, if the ID is known ??
According to documents: https://developers.google.com/drive/v2/reference/files/delete

Someone Look like this :
B4X:
DELETE https://www.googleapis.com/drive/v2/files/0B5LqWVCwfFwvdmFNejNnMkhkajg?key={YOUR_API_KEY}
GET https://www.googleapis.com/drive/v2/files?key={YOUR_API_KEY}
POST https://www.googleapis.com/drive/v2/files/0B5LqWVCwfFwveEo0MGh2eUdTams/copy?key={YOUR_API_KEY}
POST https://www.googleapis.com/drive/v2/files/0B5LqWVCwfFwveEo0MGh2eUdTams/trash?key={YOUR_API_KEY}
 
Last edited:

Paulsche

Well-Known Member
Licensed User
Longtime User
1. Upload in a folder not work. Folder create is ok, but file not uploaded in the folder "Temp",
what is wrong ?
googleDrive.UploadFile(datei, File.DirRootExternal&"/"&driveBackupPath, datei, "Temp",GD_Datei_ID)

2. Upload a zipped file "Test.zip" > 53MB in root give a Memory Error,
20MB was ok.
For this reason I would like to upload the individual files to a folder.
 

iz0ndg

Active Member
Licensed User
Longtime User
Hi DAVFLA,
Thank's for sharing your work.
Unfortunately for me the source does not work, uploaded files are always 'untitled' and I do not know why.
However, to speed up the search without downloading the complete list of the files(Especially if the file does not exist), I developed this sub that seems to work.
to be called instead of 'ShowTheFileList'.

B4X:
' ##### This is the Sub Added #####
Sub SearchTheFileList
   ProgressDia(True, strTEXT_WAIT_Filelist)
   FileListResult = ""
  
   GetFileList.Initialize(Me) : GetFileList.Tag = "GetFileList"
   Log(DriveListLink & "?access_token=" & myAccessToken & "&q=trashed+%3D+false+and+title%3D%27"& mySearchingFilename &"%27&maxResults=" & MaxResults)
   GetFileList.Download(DriveListLink & "?access_token=" & myAccessToken & "&q=trashed+%3D+false+and+title%3D%27"& mySearchingFilename &"%27&maxResults=" & MaxResults)
End Sub
'##########################
'Searching on Google Drive for a file with the filename. If founded the function returns the file ID, otherwise it returns ""
'This can need a lot of time if many files storage on Google Drive.
'If more than one file with the same filename found, the first result will return
'
'Event : FileFound(ID as String)
Sub SearchForFileID(Filename As String)
   IsSearchingFilename = True
   mySearchingFilename = Filename
'   ShowTheFileList
   SearchTheFileList '<- CALL
End Sub

Let me know if it works and if you insert it in the library. o_O
 

Paulsche

Well-Known Member
Licensed User
Longtime User
Has anyone ever managed to upload a file to a folder on GoogleDrive?
 

Paulsche

Well-Known Member
Licensed User
Longtime User
Error by upload a file with 53MB.
java.lang.OutOfMemoryError: Failed to allocate a 67092748 byte allocation with 16777216 free bytes and 59MB until OOM

What is the problem ?
A file with 20 MB is uploaded without problems?
 

DonManfred

Expert
Licensed User
Longtime User
Top