[fpc-pascal] googleapi google spreadsheet

lcy lcynet at lcy.net
Fri Dec 6 20:32:04 CET 2019


Hi Michael, thank you for fixing!

I'm still had some problems to use your googlesheets.pp the google
spreadsheet. As posted in the Lazarus forum:
https://forum.lazarus.freepascal.org/index.php/topic,47612.msg341608.html#ms
g341608

I use the calendar demo project
(\lazarus\components\googleapis\demo\calendar) as a starting point and
modified it 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);
{$ELSE}
  FClient.WebClient:=TFPHTTPWebClient.Create(Self);
{$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; 
-----------------------------------------------------

If I press the "Fetch" button the following exception is raised in the old
restbase.pp version (with the your new restbase.pp is another exception):
-----------------------------------------------------
[Debugger Exception Notification]
Project GoogleSpreadSheet raised exception class 'ERESTAPI' with message:
TValueRange: unsupported array element type : tkDynArray
-----------------------------------------------------

The good news is that google really sends 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 (from googlesheets.pp) because 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 ( in this
case is an 2 dimensional array). How can it be filled with data. 

Kind regards,
jus

-----Original Message-----
From: Michael Van Canneyt [mailto:michael at freepascal.org] 
Sent: Freitag, 6. Dezember 2019 12:32
To: lcynet at lcy.net; FPC-Pascal users discussions
Subject: Re: [fpc-pascal] googleapi google spreadsheet



On Wed, 4 Dec 2019, lcy wrote:

> I'm trying to fiqure out how to use google spreadsheet with lazarus. 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 it 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.
> Can someone help?

I just did some fixes in google api so it will work with latest trunk, but
they have nothing to do with TApplication.ProcessAsyncCallQueue.

The google components work independent of the ProcessAsyncCallQueue
procedure.

Michael.



More information about the fpc-pascal mailing list