Gsheet
Author: Fernando Arevalo
Version: 1.0
Functions:
Gsheetplus
Author: Fernando Arevalo
Version: 1.0
Functions:
NOTE:
This library is not free, because, it took a lot of time and gray hair to create all the methods and learn how the api works.
Please write GSheets or GSheetplus in the order description, thanks.
Thanks for your understanding.
This library depends the Google OAuth2 class:
follow the tutorial in this topic to create your project in google console developer, enable google dive and google sheets apis, make sure to add your package name to your project, and create an oauth screen.
Add this in your manifest:
Read example for v4 api:
Read example with Gsheets
Example connect:
Advantages:
Download Gsheetsplus:
Download Gsheets:
gsheets2json.xyz
Example B4A:
Important in the verification screen of your project in google cloud activate this permission:
Important when generating a key for android activate this:
Example google sheet:
Example api
Author: Fernando Arevalo
Version: 1.0
Functions:
- Process_Globals As String
- Initialize (ClientId As String)
- Initialize(ClientId As String,ClientSecret As String)
- SpreadsheetsId As String
The ID of your document. This is the big long aplha-numeric code in the middle of the document's URL. - Sheets_name As String
Name of the sheet we are going to work on - Sub delete(id As Int)
id: row number to delete - Updatesheet(id As String, l As List)
id: row number to Update and l: list of new items - UpdateSheet_range(range As String, value As String)
range: position of the value to be updated example: "A2". value: new value - insert_list(l As List)
l: list of new items, these items will be added in the next empty row( if a list is created with the total or partial elements of a database it will be added as a single query immediately to your sheet)
Gsheetplus
Author: Fernando Arevalo
Version: 1.0
Functions:
- Process_Globals As String
- Initialize (ClientId As String)
- Initialize(ClientId As String,ClientSecret As String)
- SpreadsheetsId As String
The ID of your document. This is the big long aplha-numeric code in the middle of the document's URL. - Sheets_name As String
Name of the sheet we are going to work on - Sub delete(id As Int)
id: row number to delete - Updatesheet(id As String, l As List)
id: row number to Update and l: list of new items - UpdateSheet_range(range As String, value As String)
range: position of the value to be updated example: "A2". value: new value - insert_list(l As List)
l: list of new items, these items will be added in the next empty row( if a list is created with the total or partial elements of a database it will be added as a single query immediately to your sheet) - copytodrive(title As String,sheetcopy As String)
creates a copy in the drive of the account with which you enter a selected sheet you must define the name of the new spreadsheet (title) and the name of the sheet to copy (sheetcopy) - createtitle( l As List, sheetsname As String, fontsize As Int,bold As Boolean)
l: list of titles, sheetsname: name of the sheet where the titles will be inserted - create_spreadsheets(title1 As String)
title: name of the new spreadsheet - create_sheets(name_sheets As String,SpreadsheetId As String)
name_sheets: name of the new sheet, SpreadsheetId:The ID of your document - deletesheet(sheetsname As String )
name_sheets: name of the sheet for delete into spreadsheet - newspreadsheetsid As String
allows to retrieve the id after creating a new spreadsheet or after backing up one in drive to save it in a database or variable it is recommended to put a wait of 2s before calling the value of this variable - newnamesheet As String
allows you to retrieve the name of the new sheet created to save it in a database or variable it is recommended to wait for 2s before calling the value of this variable
NOTE:
This library is not free, because, it took a lot of time and gray hair to create all the methods and learn how the api works.
Please write GSheets or GSheetplus in the order description, thanks.
Thanks for your understanding.
This library depends the Google OAuth2 class:
[class][B4X] Google OAuth2
GoogleOAuth2 class is compatible with B4A, B4i and B4J (new). It is no longer possible to use WebView to implement Google's OAuth2 authentication. The solution is to open the default browser and set the redirection uri in such a way that the browser will redirect the response back to our app...
www.b4x.com
Add this in your manifest:
manifest:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="$PACKAGE$" />
</intent-filter>
)
Read example for v4 api:
Read sheets:
Sub GetSheet
table1.ClearAll
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://sheets.googleapis.com/v4/spreadsheets/17YACjfqxKHDCXM_N7Jnq9BC_KzzkEgXLKzHDwaIM5Zs/values/Example!A2:Z?key=xxxxxxxxxxxxxxxxxxxxxxxxx")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(j.GetString.Trim)
Dim root As Map = parser.NextObject
'Dim majorDimension As String = root.Get("majorDimension")
Dim values As List = root.Get("values")
For Each colvalues As List In values
Dim id1 As Int = colvalues.Get("4")
Dim create As String = colvalues.Get("3")
Dim Telephone1 As Int = colvalues.Get("0")
Dim Age1 As Int = colvalues.Get("2")
Dim Name1 As String = colvalues.Get("1")
If colvalues.Size > 0 Then
table1.AddRow(Array As String(id1,Telephone1,Name1,Age1,create))
End If
Next
Dim range As String = root.Get("range")
Log(range)
End If
j.Release
End Sub
Read example with Gsheets
ReadGsheet Gsheets::
Sub GetSheet
Table1..ClearAll
s.GetSheet(Me)
Wait For get_result(x As List)
For Each col As Map In x
Table1.AddRow(Array As String(col.Get("1"),col.Get("Téléphone"),col.Get("Name"),col.Get("Age"),col.Get("created")))
Next
End Sub
Example connect:
Example connect:
#Region Activity Attributes
#FullScreen: false
#IncludeTitle: FALSE
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim s As GSheets
Private conect1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
s.Initialize("xxxxxxxxxxxxxxxx.apps.googleusercontent.com")'your Clientid google developers console, activate google drive api and google sheets api
s.Sheets_name = "Example"
s.SpreadsheetsId = "1FHx-a_a4afTQ3L5hXJIOttCVaJNngO3113E-qqFOjbk"
Activity.LoadLayout("sheets1")
End Sub
'Connect
Sub connect1_Click
s.connect
End Sub
Sub Activity_Resume
s.oauth2.CallFromResume(Activity.GetStartingIntent)
End Sub
Advantages:
- It is not linked to paying an external api
- the google sheet api is totally free
- You can integrate multiple apps into a single project in the google console
- Easy to use and integrate
Download Gsheetsplus:
Download Gsheets:
gsheets2json.xyz
Example B4A:
Important in the verification screen of your project in google cloud activate this permission:
Important when generating a key for android activate this:
Example google sheet:
Example api
Attachments
Last edited: