RTC Forums

Subscription => Support => Topic started by: HelgeLange on February 07, 2017, 05:04:32 PM



Title: How make that php JSOn call in RTC
Post by: HelgeLange 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 :)
But I don't even know where to begin such a request... and how to put fields and everything.. any hint ?

thanks, Helge


Title: Re: How make that php JSOn call in RTC
Post by: D.Tkalcec (RTC) 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


Title: Re: How make that php JSOn call in RTC
Post by: HelgeLange 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..


Title: Re: How make that php JSOn call in RTC
Post by: D.Tkalcec (RTC) 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


Title: Re: How make that php JSOn call in RTC
Post by: HelgeLange 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


Title: Re: How make that php JSOn call in RTC
Post by: HelgeLange on February 10, 2017, 09:09:14 PM
update: Works out of the box just as you wrote it. Great job, Danijel


Title: Re: How make that php JSOn call in RTC
Post by: D.Tkalcec (RTC) on February 10, 2017, 09:22:04 PM
8) Thanks for your feedback.

Best Regards,
Danijel Tkalcec