Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

Google APIs

23 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

Some of you may have noticed that a package 'Google APis' has been added to FPC in subversion. These contain the Google APIs as generated from the Google Discovery Service (~70 APIS).

I am of the opinion that such Web APIs have meanwhile the same importance as the native APIS that make up the desktop; the world is increasingly connected to Internet, and Google, MS Office365 apis (and many others) will become more and more part of the toolset of a programmer.

Object Pascal Programmers should not be left behind.

Mattias Gaertner kindly gave permission to add a package to the 'components' directory of Lazarus. It will register the Google API components on the component palette (it uses the images provided by Google itself)

Many of the APIS will probably not be used by most programmers, but some of the core APIs will be useful for a lot of people:

Google Calendar, Google Drive, Google Tasks, Google Mail, Blogger, Youtube etc.

There are already 4 example programs in the package directory, I will add more as time permits (Google Mail and Translate are definitely on my list).

Note: you will need to create OAuth client ID and secret keys to make them work.

The components as committed to Lazarus SVN will compile out of the box with FPC 3.1.

The components can also be compiled with FPC 2.6.4 (in fact they were developed with FPC 2.6.4) but then some extra files must be copied from the FPC 3.1 repository to the components dir in lazarus. (I will commit instructions for this later on)

One of the design goals was to be able to use the various TCP/IP implementations for FPC; FPC 2.6.4 will only work with Synapse, but since 3.1 contains support for the HTTPS protocol, TFPHTTPClient can be used in 3.1.

Some of the components have been used in some private projects, so they work, but I would welcome experiences, suggestions for improvement, comments.

One thing which I still plan to do is to adapt the code generator so it also creates fpdoc documentation. (the code generator is committed to SVN)

If I broke something in the lazarus SVN or forgot a file (always an option ;) ) please let me know and I will fix it ASAP. But if you don't install the package, there should be no side effects to the commit.

For those of you that read Blaise Pascal magazine: the Google APIs will be featured in the next issue (issue 41 for the English version).

As usual, comments, suggestions and contributions welcome.

Michael.

PS. The REST API for MS Office365 is next.

Reply by email

William Ferreira
to Michael Van Canneyt

GCalendar will be very welcome!

William de Oliveira Ferreira

Programador Web/Desktop

Show quoted text 65 lines
(32) 8412 1897 - Whatsapp Date: Thu, 7 May 2015 23:00:45 +0200 From: To: ; ; Subject: [Lazarus] Google APIs Hello, Some of you may have noticed that a package 'Google APis' has been added to FPC in subversion. These contain the Google APIs as generated from the Google Discovery Service (~70 APIS). I am of the opinion that such Web APIs have meanwhile the same importance as the native APIS that make up the desktop; the world is increasingly connected to Internet, and Google, MS Office365 apis (and many others) will become more and more part of the toolset of a programmer. Object Pascal Programmers should not be left behind. Mattias Gaertner kindly gave permission to add a package to the 'components' directory of Lazarus. It will register the Google API components on the component palette (it uses the images provided by Google itself) Many of the APIS will probably not be used by most programmers, but some of the core APIs will be useful for a lot of people: Google Calendar, Google Drive, Google Tasks, Google Mail, Blogger, Youtube etc. There are already 4 example programs in the package directory, I will add more as time permits (Google Mail and Translate are definitely on my list). Note: you will need to create OAuth client ID and secret keys to make them work. The components as committed to Lazarus SVN will compile out of the box with FPC 3.1. The components can also be compiled with FPC 2.6.4 (in fact they were developed with FPC 2.6.4) but then some extra files must be copied from the FPC 3.1 repository to the components dir in lazarus. (I will commit instructions for this later on) One of the design goals was to be able to use the various TCP/IP implementations for FPC; FPC 2.6.4 will only work with Synapse, but since 3.1 contains support for the HTTPS protocol, TFPHTTPClient can be used in 3.1. Some of the components have been used in some private projects, so they work, but I would welcome experiences, suggestions for improvement, comments. One thing which I still plan to do is to adapt the code generator so it also creates fpdoc documentation. (the code generator is committed to SVN) If I broke something in the lazarus SVN or forgot a file (always an option ;) ) please let me know and I will fix it ASAP. But if you don't install the package, there should be no side effects to the commit. For those of you that read Blaise Pascal magazine: the Google APIs will be featured in the next issue (issue 41 for the English version). As usual, comments, suggestions and contributions welcome. Michael. PS. The REST API for MS Office365 is next. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150507/29235406/attachment.html>

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt: Some of you may have noticed that a package 'Google APis' has been added to FPC in…
Michael Van Canneyt wrote 11 lines
Hello, Some of you may have noticed that a package 'Google APis' has been added to FPC in subversion. These contain the Google APIs as generated from the Google Discovery Service (~70 APIS). I am of the opinion that such Web APIs have meanwhile the same importance as the native APIS that make up the desktop; the world is increasingly connected to Internet, and Google, MS Office365 apis (and many others) will become more and more part of the toolset of a programmer.

Are these really APIs, i.e. an interface between an application program and a local library, or are they actually communication protocols?

https://xkcd.com/1481/ applies.

Perhaps FPC/Lazarus, which is already a large project, should package things which take a URI as a parameter and return HTML/XML/JSON etc. separately.

Also there's the risk that Google will change or discontinue a service arbitrarily. They don't exactly have a good record in that area.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Lukasz Sokol
to Michael Van Canneyt: Some of you may have noticed that a package 'Google APis' has been added to FPC in…
Michael Van Canneyt wrote 15 lines
Hello, Some of you may have noticed that a package 'Google APis' has been added to FPC in subversion. These contain the Google APIs as generated from the Google Discovery Service (~70 APIS). I am of the opinion that such Web APIs have meanwhile the same importance as the native APIS that make up the desktop; the world is increasingly connected to Internet, and Google, MS Office365 apis (and many others) will become more and more part of the toolset of a programmer. Object Pascal Programmers should not be left behind.

Thanks * 10^6 ;)

Michael. PS. The REST API for MS Office365 is next.

LibreOffice is said to also developing theirs
https://libreoffice-from-collabora.com/icewarp-and-collabora-are-working-on-libreoffice-online-document-editing-an-open-source-alternative-to-google-apps-office-365/

;)

el es

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd: Are these really APIs, i.e. an interface between an application program and a local…
Mark Morgan Lloyd wrote 17 lines
Michael Van Canneyt wrote: > Hello, > > Some of you may have noticed that a package 'Google APis' has been added to > FPC in subversion. > These contain the Google APIs as generated from the Google Discovery > Service (~70 APIS). > > I am of the opinion that such Web APIs have meanwhile the same importance > as the native APIS that make up the desktop; the world is increasingly > connected to Internet, and Google, MS Office365 apis (and many others) will > become more and more part of the toolset of a programmer. Are these really APIs, i.e. an interface between an application program and a local library, or are they actually communication protocols? https://xkcd.com/1481/ applies.

This is a sterile distinction. It is the only way to communicate with Google. it is, for all practical purposes, the API.

They also call it the API, for good reason.

Perhaps FPC/Lazarus, which is already a large project, should package things which take a URI as a parameter and return HTML/XML/JSON etc. separately.

No. For me, this is at the same level as the Win32 headers or Mac OS headers.

Whether there is a protocol involved or not is irrelevant for me. It's about making functionality available.

Also there's the risk that Google will change or discontinue a service arbitrarily. They don't exactly have a good record in that area.

This is web programming. Things change fast. I am aware of this. The files are generated using a tool, and the tool is also in SVN.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
"Michael Van Canneyt" wrote
> > Also there's the risk that Google will change or discontinue a service

arbitrarily. They don't exactly have a good record in that area.

This is web programming. Things change fast. I am aware of this. The files are generated using a tool, and the tool is also in SVN.

But maybe FPC's release cycle is too slow then. Maybe a separate fppkg would be better (like lnet) as those can be updated faster...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150508/fe031e4f/attachment.html>

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 11 lines
Am 08.05.2015 10:30 schrieb "Michael Van Canneyt" : > >> >> Also there's the risk that Google will change or discontinue a service arbitrarily. They don't exactly have a good record in that area. > > > This is web programming. Things change fast. I am aware of this. > The files are generated using a tool, and the tool is also in SVN. But maybe FPC's release cycle is too slow then. Maybe a separate fppkg would be better (like lnet) as those can be updated faster...

Let's not exaggerate. These APIS are around for years.

And the idea is to distribute FPC's own packages using fppkge anyway, exactly to be able to release faster.

Michael.

Reply by email

markbass72

hi, I am very happy of the addition of this package, great work and, of course, thanks!

I can't compile due to following error

reggoogleapi.pp(14,3) Fatal: Cannot find restbase used by reggoogleapi
of package lazgoogleapis.

fpc 2.6.5
lazarus trunk

Reply by email

Michael Van Canneyt
to markbass72
markbass72 wrote 9 lines
hi, I am very happy of the addition of this package, great work and, of course, thanks! I can't compile due to following error reggoogleapi.pp(14,3) Fatal: Cannot find restbase used by reggoogleapi of package lazgoogleapis. fpc 2.6.5

You need FPC 3.1 for all this to work 'out of the box'.

But:

The code can be compiled with 2.6.4/2.6.4, but then you must copy the source files from the FPC SVN repository to the lazarus component directory. You will also need to install the synapse package then.

I have updated the README.txt with the necessary instructions. I also did some fixes using some IFDEFS.

I will see about making a ZIP file available so people do not need access to FPC SVN.

Michael.

Reply by email

markbass72
to Michael Van Canneyt
Michael Van Canneyt wrote 16 lines
You need FPC 3.1 for all this to work 'out of the box'. But: The code can be compiled with 2.6.4/2.6.4, but then you must copy the source files from the FPC SVN repository to the lazarus component directory. You will also need to install the synapse package then. I have updated the README.txt with the necessary instructions. I also did some fixes using some IFDEFS. I will see about making a ZIP file available so people do not need access to FPC SVN.

To compile with fpc 2.6.4, I realized a script to update folder ../lazarus/components/googgleapis/2_6_4

Just create a script (e.g.: getgoogle.sh) inside this folder and paste following content.
This script populates the current folder with needed sources (as specified in README.txt).

#/bin/bash

function ExitFromScript()
{
echo ERROR: incorrect path!
echo You must execute this script from folder:
.../lazarus/components/googleapis/2_6_4
exit
}

pwd|grep "/2_6_4$" || ExitFromScript
echo Folder: OK!

[ ! -d /tmp/googleapi ] && mkdir /tmp/googleapi
svn co http://svn.freepascal.org/svn/fpc/trunk/packages/googleapi/src/ /tmp/googleapi/
cp /tmp/googleapi/* .

[ ! -d /tmp/fcl-web ] && mkdir /tmp/fcl-web
svn co
http://svn.freepascal.org/svn/fpc/trunk/packages/fcl-web/src/base/ /tmp/fcl-web/
cp /tmp/fcl-web/fpoauth2.pp .
cp /tmp/fcl-web/fphttpwebclient.pp .
cp /tmp/fcl-web/fpwebclient.pp .
cp /tmp/fcl-web/restcodegen.pp .
cp /tmp/fcl-web/restbase.pp .
cp /tmp/fcl-web/fpoauth2ini.pp .
cp /tmp/fcl-web/fpjwt.pp .

echo "-- googleapis sources --"
ls

Reply by email

Michael Van Canneyt
to markbass72
markbass72 wrote 25 lines
On 09/05/2015 17:28, Michael Van Canneyt wrote: > > You need FPC 3.1 for all this to work 'out of the box'. > > But: > > The code can be compiled with 2.6.4/2.6.4, but then you must copy the > source files from > the FPC SVN repository to the lazarus component directory. You will also > need to install the synapse package then. > > I have updated the README.txt with the necessary instructions. I also did > some fixes using some IFDEFS. > > I will see about making a ZIP file available so people do not need access > to FPC SVN. > To compile with fpc 2.6.4, I realized a script to update folder ../lazarus/components/googgleapis/2_6_4 Just create a script (e.g.: getgoogle.sh) inside this folder and paste following content. This script populates the current folder with needed sources (as specified in README.txt).

Great!! I have committed the script. rev 49018.
I don't know your name, but I entered your email address in the SVN log entry and script.

Michael.

Show quoted text 41 lines
#/bin/bash function ExitFromScript() { echo ERROR: incorrect path! echo You must execute this script from folder: .../lazarus/components/googleapis/2_6_4 exit } pwd|grep "/2_6_4$" || ExitFromScript echo Folder: OK! [ ! -d /tmp/googleapi ] && mkdir /tmp/googleapi svn co http://svn.freepascal.org/svn/fpc/trunk/packages/googleapi/src/ /tmp/googleapi/ cp /tmp/googleapi/* . [ ! -d /tmp/fcl-web ] && mkdir /tmp/fcl-web svn co http://svn.freepascal.org/svn/fpc/trunk/packages/fcl-web/src/base/ /tmp/fcl-web/ cp /tmp/fcl-web/fpoauth2.pp . cp /tmp/fcl-web/fphttpwebclient.pp . cp /tmp/fcl-web/fpwebclient.pp . cp /tmp/fcl-web/restcodegen.pp . cp /tmp/fcl-web/restbase.pp . cp /tmp/fcl-web/fpoauth2ini.pp . cp /tmp/fcl-web/fpjwt.pp . echo "-- googleapis sources --" ls -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

markbass72
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
Great!! I have committed the script. rev 49018. I don't know your name, but I entered your email address in the SVN log entry and script.

thanks for reference :)
btw my name is Marcello Basso (nomorelogic)

Reply by email

markbass72
to Michael Van Canneyt
Michael Van Canneyt wrote
Better ask questions here. I don't use the forum, I'm old school. But I have answered on the forum.

from forum:

you can set the webclient.logfile to some valid filename and examine the resulting

file after the request. It should contain the complete response of google

Note that you better use the Patch method if you're just changing some properties.
Following the response for:
FCalendarAPI.EventsResource.Update(FCurrentCalendar.ID, entry.id, Entry);

that is the same (except for 1st line where response begins with "Request : PATCH https://...") for:
FCalendarAPI.EventsResource.Patch(FCurrentCalendar.ID, entry.id, Entry);

maybe missing headers?

thanks

-------------------------------------------------------------------------------- Request : PUT
https:/events/f8umj295ncoahohqh2o8rjrsbc
Headers:
Authorization: Bearer
ya29.dAGRj9MlacyM-TxfnKGMKjpAQNhL2U61xxrMjzk05LbLHPFqYNVg6llBTpL_jj0DrxLx9TVCDBfAjw Body:
{ "description" : "bla bla bla[modified]" }
-------------------------------------------------------------------------------- Response : 400 : Bad Request
Headers:
HTTP/1.0 400 Bad Request
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
Date: Fri, 15 May 2015 09:12:07 GMT
Expires: Fri, 15 May 2015 09:12:07 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic,p=1
Accept-Ranges: none
Vary: Origin,Accept-Encoding

Body:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: text/html" }
],
"code": 400,
"message": "Unsupported content with type: text/html" }
}

Reply by email

Michael Van Canneyt
to markbass72
markbass72 wrote 22 lines
On 15/05/2015 10:22, Michael Van Canneyt wrote: > > Better ask questions here. I don't use the forum, I'm old school. > But I have answered on the forum. > from forum: > you can set the webclient.logfile to some valid filename and examine the > resulting file after the request. It should contain the complete response of google > Note that you better use the Patch method if you're just changing some > properties. Following the response for: FCalendarAPI.EventsResource.Update(FCurrentCalendar.ID, entry.id, Entry); that is the same (except for 1st line where response begins with "Request : PATCH https://...") for: FCalendarAPI.EventsResource.Patch(FCurrentCalendar.ID, entry.id, Entry); maybe missing headers?

Looks like it, a header 'Content-type: application/javascript' should be added.

Look in googleservice.pp, line 522

     Req.SetContentFromString(AInput);
There add a
   if (AMethod'GET') then
     Req.Headers.Add('Content-Type: application/json');

Strange.

I have created a calendar sync app which does both POST and PATCH. Probably I have forgotten to copy some changes to the FPC repo.

Please test and report, if this helps, I'll update the API. (I need to do some other changes anyway)

Michael.

Reply by email

Michael Van Canneyt
to Michael Van Canneyt
Michael Van Canneyt wrote 29 lines
On Fri, 15 May 2015, markbass72 wrote: > On 15/05/2015 10:22, Michael Van Canneyt wrote: >> >> Better ask questions here. I don't use the forum, I'm old school. >> But I have answered on the forum. >> > > from forum: >> you can set the webclient.logfile to some valid filename and examine the >> resulting > file after the request. It should contain the complete response of google >> Note that you better use the Patch method if you're just changing some >> properties. > > > Following the response for: > FCalendarAPI.EventsResource.Update(FCurrentCalendar.ID, entry.id, Entry); > > that is the same (except for 1st line where response begins with "Request : > PATCH https://...") for: > FCalendarAPI.EventsResource.Patch(FCurrentCalendar.ID, entry.id, Entry); > > maybe missing headers? Looks like it, a header 'Content-type: application/javascript' should be added.

I checked, I had indeed another version of googleservice.pp with the fix in it. I commited the fix, rev. 30859.

Michael.

Reply by email

Michael Van Canneyt
to markbass72
markbass72 wrote 9 lines
On 15/05/2015 12:48, Michael Van Canneyt wrote: > > I checked, I had indeed another version of googleservice.pp with the fix in > it. > I commited the fix, rev. 30859. > > Michael. Now it works!

Great, because I almost got a heart attack :)

Michael.

Reply by email

markbass72
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
On Fri, 15 May 2015, markbass72 wrote: > Now it works! Great, because I almost got a heart attack :) Michael.

please, stay away from heart attacks ok?
:)

I still have some problems with either commit 30859 and 30885.

In calendar demo, event listbox, double click event, I have added this code:

procedure TMainForm.LBEventsDblClick(Sender: TObject);
var Entry: TEvent;
begin
   Entry:=Events.items[LBEvents.ItemIndex];
   try
     Entry.summary:='new summary';
     FCalendarAPI.EventsResource.Update(FCurrentCalendar.ID, entry.id,
Entry);
     ShowMessage('event updated');
   except
     on e: exception do begin
        ShowMessage('response failed:'+#10+e.Message);
     end;
   end;
end;

It looks like a required field is missing but time fields are ok (as inserted from browser in google calendar web app). Can you help me?

Thanks in advantage,
nomorelogic

-------------------------------------------------------------------------------- Request : PUT
https://www.googleapis.com:/events/f8umj295ncoahohqh2o8rjrsbc Headers:
Content-type=application/json
Authorization: Bearer
ya29.eAE--gypYwbsLnh4YyQVrMXLMbbtHgujdHaQXlYxNRROhO0Oy6eAurHoVpetFYvamWgxdbYAiKb5RA Body:
{ "summary" : "new summary" }
-------------------------------------------------------------------------------- Response : 400 : Bad Request
Headers:
HTTP/1.0 400 Bad Request
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
Date: Tue, 19 May 2015 13:26:49 GMT
Expires: Tue, 19 May 2015 13:26:49 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic,p=1
Accept-Ranges: none
Vary: Origin,Accept-Encoding

Body:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Missing end time."
}
],
"code": 400,
"message": "Missing end time."
}
}

Reply by email

Michael Van Canneyt
to markbass72
markbass72 wrote 39 lines
On 15/05/2015 12:59, Michael Van Canneyt wrote: > > > On Fri, 15 May 2015, markbass72 wrote: > >> Now it works! > > Great, because I almost got a heart attack :) > > Michael. > please, stay away from heart attacks ok? :) I still have some problems with either commit 30859 and 30885. In calendar demo, event listbox, double click event, I have added this code: procedure TMainForm.LBEventsDblClick(Sender: TObject); var Entry: TEvent; begin Entry:=Events.items[LBEvents.ItemIndex]; try Entry.summary:='new summary'; FCalendarAPI.EventsResource.Update(FCurrentCalendar.ID, entry.id, Entry); ShowMessage('event updated'); except on e: exception do begin ShowMessage('response failed:'+#10+e.Message); end; end; end; It looks like a required field is missing but time fields are ok (as inserted from browser in google calendar web app). Can you help me?

You must use Patch, not update.

Michael.

Reply by email