RTC Forums
November 23, 2024, 09:53:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: How make that php JSOn call in RTC  (Read 7658 times)
HelgeLange
RTC Expired
*
Posts: 100


« on: February 07, 2017, 05:04:32 PM »

Hi Danijel,
sorry to bother you with this, but I'm a bit lost.
I want to talk to the google CGM, but all I find is a php call

Code:
curl_setopt($Request, CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send');
 
    curl_setopt($Request, CURLOPT_POST, 1);
 
    curl_setopt($Request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization:key=' . <<my server="" api="" key="">>));
 
    curl_setopt($Request, CURLOPT_POSTFIELDS, {"registration_ids" : ["' . <<device token="">> . '"],"data":{"message":"My message","title":"My title"}});
 
    curl_setopt($Request, CURLOPT_SSL_VERIFYPEER, false);
 
    curl_setopt($Request, CURLOPT_RETURNTRANSFER, true);
 
    $Response = curl_exec($Request);

I guess, RTC has no problem, to do the same and less cryptic Smiley
But I don't even know where to begin such a request... and how to put fields and everything.. any hint ?

thanks, Helge
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: February 07, 2017, 05:41:58 PM »

Sorry, but what you have just posted looks cryptic to me, too. Try finding better documentation for the API you want to "talk to". Maybe something that uses CURL directly would be easier to decypher than this PHP thingy.

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #2 on: February 07, 2017, 09:23:55 PM »

Code:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
  "to": "/topics/foo-bar",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}

looks like this..
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: February 07, 2017, 10:46:12 PM »

Here are the "important" bits  ...

With RtcHttpClient do
  begin
  ServerAddr:='fcm.googleapis.com';
  ServerPort:='443';
  useSSL:=True;
  AutoConnect:=True;
  end;

With RtcDataRequest do
  begin
  Client:=RtcHttpClient;
  Request.Host:='fcm.googleapis.com';
  Request.Method:='POST';
  Request.FileName:='/fcm/send';
  Request['Content-Type']:='application/json';
  Request['Authorization']:='key=AIzaSyZ-1u...0GBYzPu7Udno5aA';
  With Request.Info.newRecord('data') do
    begin
    asText['to']:= '/topics/foo-bar';
    with newRecord('data') do
      asText['message']:='This is a ... Topic Message!';
    end;
  Post;
  end;

You write the content body out from
RtcDataRequest's OnBeginRequest event ...

With TRtcDataClient(Sender) do
  Write(Request.Info.asJSON['data']);

If you expect a response, you can use this
for the OnDataReceived event  ...

With TrtcDataClient(Sender) do
  If Response.Done then
     MyResponse:=Read;

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #4 on: February 08, 2017, 12:31:47 AM »

I think I understand. I'll give it a try and keep you posted.

Thanks a lot.
Helge
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #5 on: February 10, 2017, 09:09:14 PM »

update: Works out of the box just as you wrote it. Great job, Danijel
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #6 on: February 10, 2017, 09:22:04 PM »

Cool Thanks for your feedback.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.025 seconds with 17 queries.