question

yoonjy avatar image
yoonjy asked

Using PHP, Send the message.

Hi, I tried to adapt your JAVA code in php, but the server respond with an error here my code : $RegistrationId ='amzn1.adm-xxx....'; $accessToken = 'Atc|MQEBIF-xxx....'; function sendMessageToPhone($RegistrationId, $accessToken) { $data = json_encode(array("message"=>"Hi, Amazon!", "timeStamp"=>curdate() "expiresAfter"=> "8600")); $url = ' https://api.amazon.com/messaging/registrations/'$RegisterationId'/messages'; $fp = curl_init(); curl_setopt($fp, CURLOPT_URL, $url); curl_setopt($fp, CURLOPT_HEADER, 1); curl_setopt($fp, CURLOPT_POST, 1); curl_setopt($fp, CURLOPT_SSLVERSION,3); curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($fp, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'accept = application/json', 'X-Amzn-Type-Version : com.amazon.device.messaging.ADMMessage@1.0', 'X-Amzn-Accept-Type : com.amazon.device.messaging.ADMSendResult@1.0', 'Authorization : Bearer+$accessToken') ); curl_setopt($fp, CURLOPT_POSTFIELDS, $data); $response = json_decode(curl_exec($fp),true); } sendMessageTophone($RegistrationId, $accessToken); and the response is "Sever Error" What am I doing wrong ?
amazon device messaging
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

yoonjy avatar image
yoonjy answered
"Hi, Amazon!", "timeStamp"=>curdate(), "expiresAfter"=> "8600")); $url = " https://api.amazon.com/messaging/registrations/'$RegisterationId'/messages"; $headers = array('content-type : application/json', 'accept = application/json', 'X-Amzn-Type-Version : com.amazon.device.messaging.ADMMessage@1.0', 'X-Amzn-Accept-Type : com.amazon.device.messaging.ADMSendResult@1.0', 'Authorization : Bearer .$accessToken'); $fp = curl_init(); curl_setopt($fp, CURLOPT_URL, $url); curl_setopt($fp, CURLOPT_HTTPHEADER, $headers ); curl_setopt($fp, CURLOPT_POST, 1); curl_setopt($fp, CURLOPT_HEADER, 1); curl_setopt($fp, CURLOPT_SSLVERSION,3); curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($fp, CURLOPT_POSTFIELDS, $data); $response = json_decode(curl_exec($fp),true); ?> I changed the php code (send the message). So, there are no server error. But, when i checked the Logcat of eclipse, I can't see any message(signal) that the app received. What am I doing wrong ?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

skyzoneentertainment avatar image
skyzoneentertainment answered
I also have this issue.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Yooniy, Thank you for posting. There is post where we discussed about sending message in PHP. https://forums.developer.amazon.com/forums/thread.jspa?threadID=1087&tstart=30 Some times adm message takes time to reach to the devices. Can you check one thing? While the message is successfully sent from server try to press "sync" button in the device and see whether you get call back in onMessage() in your app. Also please check what is the http response code you are receiving in the server against the send message request. You will get the details about the response codes here : https://developer.amazon.com/sdk/adm/sending-message.html#ResponseFormat In php, you can get http response code in this way: $httpCode = curl_getinfo($fp, CURLINFO_HTTP_CODE); Please revert back if the problem persists and you are unable to get any clue. Thanks.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.