Forum > Networking and Web Programming

Free Pascal and sending push-notifications via FCM

(1/4) > >>

JohnvdWaeter:
Hi All,
I recall having read somewhere that someone is working on using Free Pascal to send push-notifications to a Google Firebase server.
I wrote a freepascal linux service that handled this for many years, but now Google is switching to a new protocol (v1).

Their doc doesn't help me, I'm stuck.

Is someone working on this?
tia, John

Thaddy:
Usually this is picked up by regenerating the google api package, but I am not sure.
It is pretty much automated and there are instructions on how to do that yourself.
( If I am wrong the term is Michael Automata )

rvk:
What's the problem you are experiencing when switching to
https://fcm.googleapis.com/v1/projects/xxx ?

I see I still have the legacy http in my small php script so I guess I have to switch soon  ::)

https://firebase.google.com/docs/cloud-messaging/migrate-v1

JohnvdWaeter:
Yes, the legacy protocol worked great for years, and still does.
The new V1 protocol gives me headaches....
I try (in a GUI):


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if radiobutton1.Checked then ato:=edit1.Text; // iOS FCMDevicetokenif radiobutton2.Checked then ato:=edit2.Text; // Android FCMDevicetoken    TheMessage:='{"message": {'+                              '"token":"'+ato+'",'+                              '"notification":{'+                                               '"title":"Notification title",'+                                               '"body":"Notification body" '+                                             '}}}';  projectid   := 'ellip.........6407'; access_token  := '5663a6ca0c115f787.........72b76af6c2dd5'; topost  := 'https://fcm.googleapis.com/v1/projects/'+projectid+'/messages:send HTTP/1.1';  memo2.Lines.Add(topost);  IdHTTP := TIdHTTP.Create(nil);  try    IdHTTP.ProtocolVersion     := TidHttpProtocolversion.pv1_1;    idHttp.HTTPOptions         := [hoKeepOrigProtocol,hoForceEncodeParams];    IdHTTP.Request.ContentType := 'application/json';    IdHTTP.Request.Charset     := 'UTF-8';    idhttp.HandleRedirects     := True;    IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer '+access_token;     try     JsonToSend := TStringStream.Create(TheMessage, TEncoding.UTF8);     response   := IdHTTP.Post(topost, jsontosend);     Memo2.Lines.Add('resp:'+response);     except     on E: EIdHTTPProtocolException do      begin       Memo2.Lines.add(IntToStr(E.ErrorCode) + ' ' + E.Message);      end;     on E:Exception do     begin      Memo2.Lines.add('Error: '#13 + E.ClassName + #13 + E.Message);     end;    end;   finally    IdHTTP.Free;  end;   jsonToSend.Free;    
But this gives me an error: 400 HTTP/1.0 400 Bad Request

rvk:

--- Quote from: JohnvdWaeter on May 08, 2024, 12:55:38 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- topost  := 'https://fcm.googleapis.com/v1/projects/'+projectid+'/messages:send HTTP/1.1'; 
--- End quote ---
I haven't tried yet but above line is definitely wrong.
The HTTP/1.1 shouldn't be there. It isn't part of the URL !!

Try it without.
If it doesn't work, I'll create a working example here (but not with Indy but with fphttp).

Navigation

[0] Message Index

[#] Next page

Go to full version