Corona Cloud Push Notifications

I’m confused about the implementation of the cloud push notifications.  I want to use them without using any of the other cloud game features.

So I use this code to register the device:

local coronacloud = require “corona-cloud-core”

coronacloud.init(cloudaccesskey,cloudsecretkey)

coronacloud.registerDevice(event.token)            

OK, fine, so now a bunch of devices are registered

Now, I’m confused about how to send the actual push message.  Yes, I know you

do it with PHP and curl. But the example doesn’t offer much explanation, and only says:

auth_token (required)

String. Authentication Token of user.

message (required)

String. Message to be sent.

curl --user bd62f3256a0ff879595e0aa7c0376e9d21b46590:078e95efd0686725b6b10bd8769bc6f767e0183b -X POST -d “auth_token=4f705899f903950001000016&message=hello” https://api.coronacloud.com/notification.json

I don’t understand what the auth_token is or where it comes from.

I assume that the cloud is saving all the devices somewhere so that with one php send command I can use the cloud to send a messaage to ALL devices that were previous registered, correct?  I assume I don’t still have to save auth_tokens gathered from each device when they were registered, right?  If that was true what would be the point of having the cloud? 

So then, what is the auth_token, and how do you get it?  I think the items after the --user are cloudaccesskey:cloudsecretkey but I have no idea what the auth_toke is.

Does anybody have an example of the exact PHP code used to send ALL registered devices a push message using Corona Cloud?

 

Hi,

Actually this is a typo, auth_token is not required for this call. I have already requested for the doc to be updated.

The other typo is that this is a POST call not a GET.

So assuming you are going to send this Push Broadcast Notification from your PHP site.

Setup the basic authentication:

Username: [Access Key]

Password: [Secret Key]

The structure of the call should look something like this:

https://api.coronalabs.com/notifications.json?message=Hello

I am not familiar with PHP but found this link that shows how to use the PHP cURL extension http://www.lornajane.net/posts/2010/three-ways-to-make-a-post-request-from-php

Hope this helps.

-Mohamed

Thanks Mohamed.
 

If PHP isn’t normally used to send the push messages, what normally is used, and how was this facility tested??

I took a look at the page you suggested, but I’m still not clear on where you’d add the access key and secret key?

$url = “https://api.coronalabs.com/notifications.json?message=Hello”;
$ch = curl_init($url);
 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
$response = curl_exec($ch);
curl_close($ch);

Hi, quick question, would using the Push Notification on the Corona Cloud Portal work for what you need?

You can basically log into the portal, go to “Push Notification -> Send Push Notification” and just past the info you want to send, and send it from there.

Can you tell me more about what you want to do, specifically what is the trigger for sending the push?

In any case, did some looking around, and apparently this is how you can set the basic auth:

curl_setopt($process, CURLOPT_USERPWD, $username . “:” . $password);

Thanks

-Mohamed

I haven’t had a proper play yet but I thought it would be something like this -

$data = array('username' =\> 'Access Key', 'Password' =\> 'Secret Key'); curl\_setopt($curl\_object, CURLOPT\_POSTFIELDS, $data)

Dave

Hey Mohamed,

What I’m trying to do is send a 2 single push messages, weekly, that would each be sent to every user of an application.  Without the cloud, it seems you’d have to send the messages again and again, once each to every single individual user whom you’ve saved the tokens for.  But, I assume with the cloud, you can send a push message just once, and the Corona Cloud will send that one push message to every individual user.

OK, so now back to what’s happening with the portal – that’s another problem.

It seems I have it set up properly - In Push settings I have Google disabled.  In Apple Push Notification Settings I have created a Development & Production Passphrases, I have also successfully uploaded the Development Certificate and the Production Certificate; I have Status set to Enabled, and Use THe Following Servers Set to “Development/Sandbox” – I don’t know what HTTP Post Push Notification Settings means (I can’t find any documentation anywhere) but I’ve tried both Enabled and Disabled.

Then if I go into the portal, choose the App, click “Push Notification”, then “Send Push Notification”.

I type, HELLO MOHAMED, CHECK THIS OUT where it says Message, and check “All Users”, when I click Submit, I’ve been getting this response for the last 3 days:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it shortly.

Hi greglosang, I’ll get the team to look at this straight away.

Thanks

-Mohamed

Mohamed,

Another concern:

In corona-cloud-core.lua, it appears that coronaCloudController.authToken is a required variable when

calling coronaCloudController.registerDevice (it’s used on line: 487)

The problem is that this variable, coronaCloudController.authToken is never set anywhere!  The only

place it would be set that I can tell is either in:

coronaCloudController.loginAPI

or

coronaCloudController.loginFacebook

But since I’m only wanting to use the Push Notifications, not any of the other features, I would never have a user logging in at all, so that means the authToken would never be set.

So is it really possible to use ONLY the Push Notification feature?  The devices would need to each be registered without any logging in, they would be registered when the user first indicates they want the notifications.

Then, in PHP I’d like to use a single command to then send a message to all registered users.

Is this possible?

Why is coronaCloudController.authToken used in coronaCloudController.registerDevice?  Or is it (hopefully) just nil and ignored?

I’m also not having any luck with the PHP to send the notification; here’s what I’ve got:

This is the response I’m getting (I changed a few chars after Authorization Basic):

Error Code:Array ( [url] => https://api.coronalabs.com/notifications.json?message=Hello [content_type] => [http_code] => 400 [header_size] => 66 [request_size] => 353 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.55188 [namelookup_time] => 0.270326 [connect_time] => 0.312304 [pretransfer_time] => 0.509163 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => -1 [starttransfer_time] => 0.55183 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 54.235.69.115 [redirect_url] => [request_header] => POST /notifications.json?message=Hello HTTP/1.1 Authorization: Basic NxxxxxzA0ODgwMjAwMxxxxxDg4NzICHangedThisZGZjNTU3YxxmMzoyYzZmxzBlZGFhODI5xxxxxjk1OGNlMzI2YWM2MWJhNzcxYmRmYjZj Host: api.coronalabs.com Accept-Encoding: deflate, gzip Accept: application/xml Content-Type: application/xml; charset=UTF-8 Content-Length: -1 Expect: 100-continue ) Call Failed 1

This is my PHP code:

<!DOCTYPE html>

<html lang=“en”>

<head>

</head>

<body>

<?php

$accesskey = “accesskeyfromcoronacloud”;

$secretkey = “secretkeyfromcoronacloud”;

$url = “https://api.coronalabs.com/notifications.json?message=Hello”;

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);

curl_setopt($curl, CURLOPT_USERPWD, “{$accesskey}:{$secretkey}”);

$headers = array();

       $headers[] = ‘Accept: application/xml’;

       $headers[] = ‘Content-Type: application/xml; charset=UTF-8’;

       

 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

 curl_setopt($curl, CURLOPT_POST, TRUE);

 curl_setopt($curl, CURLOPT_VERBOSE, 1);

 curl_setopt($curl, CURLOPT_HEADER, TRUE);

 curl_setopt($curl, CURLINFO_HEADER_OUT, true);

 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

 curl_setopt($curl, CURLOPT_ENCODING, ‘’);

 curl_setopt($curl, CURLOPT_TIMEOUT, 15);

 curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);

 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);

$response = curl_exec($curl);

$resultStatus = curl_getinfo($curl);

print “Error Code:” . curl_error($curl);

                                   

if($resultStatus[‘http_code’] == 200) {

    echo $response;

} else {

    echo 'Call Failed '.print_r($resultStatus);                         

}

curl_close($curl);

?>

</body>

And if I change to this:

curl_setopt($curl, CURLOPT_USERPWD, $accesskey.":".$secretkey);

I get this:

Error Code:Array ( [url] => https://api.coronalabs.com/notifications.json?message=Hello [content_type] => [http_code] => 400 [header_size] => 66 [request_size] => 353 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.406769 [namelookup_time] => 0.189662 [connect_time] => 0.2322 [pretransfer_time] => 0.336428 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => -1 [starttransfer_time] => 0.406697 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 184.73.229.231 [redirect_url] => [request_header] => POST /notifications.json?message=Hello HTTP/1.1 Authorization: Basic NGIChangedSomeOfThismNDg4NzdkIChangedSomeOfThisyYzZmNzBlZGFhOIChangedSomeOfThisM2MWJhNzcxYmRmYjZj Host: api.coronalabs.com Accept-Encoding: deflate, gzip Accept: application/xml Content-Type: application/xml; charset=UTF-8 Content-Length: -1 Expect: 100-continue ) Call Failed 1

Hi greglosang, 

Currently users need to login at least once so they can get an auth_token. 

As I have suggest to a different user on the forum; we are looking into how we can allow new user creation without an email, but in the mean let me suggest this workaround.

You can prompt your user to enter a UserName only, and then you can auto create the email address transparently.

I would suggest you do something like this: [appName]+[UserName]@gmail.com; where [appName]@gmail is an account you have already.

So it might look something like this: myapp+greglosang@gmail.com.

After the user logins in and gets their auth__token, you can register their device.

Give it a try and let me know.

Thanks

-Mohamed

Thanks for the info Mohamed, but it doesn’t make sense in my Apps to require users to sign in just so they can get push notifications.

I guess this makes the Corona Cloud useless for me, for now.

Isn’t it possible just to save the device tokens then send a push message to all the tokens the same way it works if you

weren’t using Corona?  Apple doesn’t require any kind of a signin in order to receive push notifications on devices.

I guess it’s back to writing my own php and just saving the device tokens myself.

Hi greglosang,

I will add your comments/requirement to our system and make sure we look into how we can address it in the future.

Your situation is a unique one, because you are broadcasting to everyone and don’t have any requirement to segment, where you will need to be able to have another level of ID for your users.

What I would recommend is that you give our system a go and see how it works out for you, as I am sure the effort to transparently logging-in your users is many factors easier, and quicker than setting up the whole process for yourself.

In any case, best of luck and feel free to let us know how we can assist.

Thanks

-Mohamed 

Mohamed,

Are you implying by constructing the email address and using the login API call there is a way to login the user without any intervention on the user’s behalf other than the original system prompt that they want push notifications?

Hi,

Sure, there is no need to display anything to the user at any point.

You can make all registration and login calls transparently with no UI.

Thanks

-Mohamed

Hi,

Actually this is a typo, auth_token is not required for this call. I have already requested for the doc to be updated.

The other typo is that this is a POST call not a GET.

So assuming you are going to send this Push Broadcast Notification from your PHP site.

Setup the basic authentication:

Username: [Access Key]

Password: [Secret Key]

The structure of the call should look something like this:

https://api.coronalabs.com/notifications.json?message=Hello

I am not familiar with PHP but found this link that shows how to use the PHP cURL extension http://www.lornajane.net/posts/2010/three-ways-to-make-a-post-request-from-php

Hope this helps.

-Mohamed

Thanks Mohamed.
 

If PHP isn’t normally used to send the push messages, what normally is used, and how was this facility tested??

I took a look at the page you suggested, but I’m still not clear on where you’d add the access key and secret key?

$url = “https://api.coronalabs.com/notifications.json?message=Hello”;
$ch = curl_init($url);
 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
$response = curl_exec($ch);
curl_close($ch);

Hi, quick question, would using the Push Notification on the Corona Cloud Portal work for what you need?

You can basically log into the portal, go to “Push Notification -> Send Push Notification” and just past the info you want to send, and send it from there.

Can you tell me more about what you want to do, specifically what is the trigger for sending the push?

In any case, did some looking around, and apparently this is how you can set the basic auth:

curl_setopt($process, CURLOPT_USERPWD, $username . “:” . $password);

Thanks

-Mohamed

I haven’t had a proper play yet but I thought it would be something like this -

$data = array('username' =\> 'Access Key', 'Password' =\> 'Secret Key'); curl\_setopt($curl\_object, CURLOPT\_POSTFIELDS, $data)

Dave

Hey Mohamed,

What I’m trying to do is send a 2 single push messages, weekly, that would each be sent to every user of an application.  Without the cloud, it seems you’d have to send the messages again and again, once each to every single individual user whom you’ve saved the tokens for.  But, I assume with the cloud, you can send a push message just once, and the Corona Cloud will send that one push message to every individual user.

OK, so now back to what’s happening with the portal – that’s another problem.

It seems I have it set up properly - In Push settings I have Google disabled.  In Apple Push Notification Settings I have created a Development & Production Passphrases, I have also successfully uploaded the Development Certificate and the Production Certificate; I have Status set to Enabled, and Use THe Following Servers Set to “Development/Sandbox” – I don’t know what HTTP Post Push Notification Settings means (I can’t find any documentation anywhere) but I’ve tried both Enabled and Disabled.

Then if I go into the portal, choose the App, click “Push Notification”, then “Send Push Notification”.

I type, HELLO MOHAMED, CHECK THIS OUT where it says Message, and check “All Users”, when I click Submit, I’ve been getting this response for the last 3 days:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it shortly.