First of all it seems that the calendar sample project (\lazarus\components\googleapis\demo\calendar) doesn't work in the trunk version Laz(2.1.0)+FPC(3.3.1) created with fpcupdeluxe anymore. After installing the googleapi and the synapse component the calendar sample compiles with success. But if I run the app lazarus stops in application.inc at the end of the "procedure TApplication.ProcessAsyncCallQueue" method. With the stable version Laz(2.0.2)+FPC(3.0.4) created with fpcupdeluxe it seems to run.
So used the stable Laz(2.0.2)+FPC(3.0.4) version and the calendar demo as a starting point for google spreadsheet.
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
begin
// Register resources.
TSheetsAPI.RegisterAPIResources;
// Set up google client.
FClient:=TGoogleClient.Create(Self);
{$IFDEF USESYNAPSE}
FClient.WebClient:=TSynapseWebClient.Create(Self);
Memo1.Lines.Add('$IFDEF USESYNAPSE');
{$ELSE}
FClient.WebClient:=TFPHTTPWebClient.Create(Self);
showmessage('Falsch!');
{$ENDIF}
FClient.WebClient.RequestSigner:=FClient.AuthHandler;
FClient.WebClient.LogFile:='requests.log';
FClient.AuthHandler.WebClient:=FClient.WebClient;
FClient.AuthHandler.Config.AccessType:=atOffLine;
// We want to enter a code.
FClient.OnUserConsent:=@DoUserConsent;
FSheetsAPI:=TSheetsAPI.Create(Self);
FSheetsAPI.GoogleClient:=FClient;
// Load configuration
LoadAuthConfig;
end;
procedure TMainForm.BFetchCalendarsClick(Sender: TObject);
var
Resource : TSpreadsheetsValuesResource;
EN : String;
i:integer;
RangeData: TValueRange;
begin
SaveRefreshToken;
RangeData:=Nil;
Resource:=Nil;
Resource := FSheetsAPI.CreateSpreadsheetsValuesResource;
try
if assigned(Resource) then
begin
Memo1.Lines.Add('resources assigned');
RangeData:= Resource.Get('****your spread sheet id****','Tabellenblatt1!A1:B3');
end;
finally
FreeAndNil(Resource);
end;
end;
The good news is that google really send the requested cells (in my case above A1:B3) back as a json string. The json string from google in my case looks like:
{
"range": "Tabellenblatt1!A1:B3",
"majorDimension": "ROWS",
"values": [
[
"quantity",
"product"
],
[
"1",
"product 1"
],
[
"2",
"product 2"
]
]
}
But the problem is that the json values cannot be saved to the TValueRange object. An exception is raised. After some debugging it seems that the "procedure TBaseObject.SetArrayElements" method in restbase.pp cannot handle the tkdynarray type. I guess the TBaseObject.SetArrayElements can only handle 1 dimensional arrays but not multidimensional arrays. My problem currently is that I didn't really understand how the TValueRange can hold a multidimensional array. How can it be filled with data. Could someone help?