Dim sSTR As String = "https://sheets.googleapis.com/v4/spreadsheets/" & sheetID & "?ranges=" & range
oauth2.GetAccessToken
Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
If Success = False Then
ToastMessageShow("Error accessing account.", True)
Return
End If
Dim j As HttpJob
j.Initialize("", Me)
j.Download2(sSTR, Array As String("key", API_KEY))
j.GetRequest.SetHeader("Authorization", "Bearer " & Token)
If j.Success Then
Log(j.GetString)
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
Dim values As List = root.Get("values")
Dim cindex, rindex As Int
Spn_Line.clear
For Each rowvalues As List In values 'get row
rindex=rindex+1
'Log("row: " & rowvalues)
For Each colvalues As String In rowvalues 'get column
cindex=cindex+1
Spn_Line.Add(colvalues)
Log(colvalues)
Log("rindex: " & rindex & "cindex: "&cindex)
Next
cindex = 0
Next
End If
j.Release
Dim sSTR As String = "https://sheets.googleapis.com/v4/spreadsheets/" & sheetID & _
"?includeGridData=true&ranges=" & range
oauth2.GetAccessToken
Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
If Success = False Then
ToastMessageShow("Error accessing account.", True)
Return
End If
Dim j As HttpJob
j.Initialize("", Me)
j.Download2(sSTR, Array As String("key", API_KEY))
j.GetRequest.SetHeader("Authorization", "Bearer " & Token)
Ok. I changed my query to this.... (minus the API_KEY)
B4X:
Dim sSTR As String = "https://sheets.googleapis.com/v4/spreadsheets/" & sheetID & "?includeGridData=true&ranges=" & range
oauth2.GetAccessToken
Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
If Success = False Then
ToastMessageShow("Error accessing account.", True)
Return
End If
Dim j As HttpJob
j.Initialize("", Me)
j.Download(sSTR)
My Log displays the results.
But, I get this error ...
B4X:
java.lang.RuntimeException: Object should first be initialized (List).
If j.Success Then
Log(j.GetString)
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
Dim sValues As List = root.Get("values")
Dim cindex, rindex As Int
Spn_Line.clear
For Each rowvalues As List In sValues 'get row
rindex=rindex+1
'Log("row: " & rowvalues)
For Each colvalues As String In rowvalues 'get column
cindex=cindex+1
Spn_Line.Add(colvalues)
Log(colvalues)
Log("rindex: " & rindex & "cindex: "&cindex)
Next
cindex = 0
Next
' Spn_Line.clear
' For Each nm As NameAndMac In btDevices
' Spn_Line.Add(nm.name)
' Next
End If
j.Release
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
Dim sheets As List = root.Get("sheets")
For Each colsheets As Map In sheets
Dim data As List = colsheets.Get("data")
For Each coldata As Map In data
Dim rowData As List = coldata.Get("rowData")
For Each colrowData As Map In rowData
Dim values As List = colrowData.Get("values")
For Each colvalues As Map In values
Dim effectiveValue As Map = colvalues.Get("effectiveValue")
Dim stringValue As String = effectiveValue.Get("stringValue")
Spn_Line.Add(stringValue)
Next
Next
Next
Next
Here "Spn_Line" is a spinner.
Getting error
B4X:
java.lang.RuntimeException: Object should first be initialized (Map).
on this line....
B4X:
Dim stringValue As String = effectiveValue.Get("stringValue")
Changed the error line code to check if "effectiveValue" has been initialized...
B4X:
Dim effectiveValue As Map = colvalues.Get("effectiveValue")
If effectiveValue.IsInitialized Then
Dim stringValue As String = effectiveValue.Get("stringValue")
Spn_Line.Add(stringValue)
End If
Leaving this post in case it helps someone (like me )
1. Please post the code AND the error message from the logs as TEXT within CODE TAGS. 2. Don't post images 3. Describe what the problem is (full sentences, not 3 words, not "my car doesn't work - guess what it is") 4. Use the search function FIRST (assume you're not the first person having that...
I've read that thread earlier too.
But, unfortunately, I cannot find the option to edit the Title of my post.
The attached screenshot is what is visible to me......
Please be kind as to mention the steps to do the same.