Ads network request

Hello!

I need some help with a network request. I’m just getting the hang of server-to-server request. I’m working with an Ad Networks offerwall. This is the URL they are asking me to setup:

In the Callback URL field, construct the callback for Supersonic to send you after a user performs an ad unit completion, for example:

http://www.mysite.com/  granting  .php?appUserId=[USER_ID]&rewards=[REWARDS]&eventId=[EVENT_ID]&itemName=[ITEM_NAME]

The values in brackets are placeholders that are replaced by actual values when ** Supersonic ** sends you the callback.

Can someone give me an example on how I can implement this into my app and how I can receive their values?

This may seem like a strange answer, but if you go to the Peanut Labs plugin documentation. There is a Server Requirements link there. PL requires this callback, most other ad providers its optional. But we provide a PHP/MySQL database script for their server to call to your server and record the data they have to share. There is a second script that your app would call to get the reward from your server and an example MySQL table create command.

Now the examples won’t run out of the box for Supersonic or any one other than PL since it has code to validate PL’s way of validating the callback and PL specific fields. But it should give you a starting point and a little bit of an explaination of the process that might get you further along.

Rob

@Rob

So, is the callback a GET or a POST?

Also, When I set the parameters, will it look like this?

params.rewards = '[REWARDS]'

im a little confused on how they are sending back the response…

Most callbacks that I’ve seen pass the key-value pairs as part of the URL, which would make them GET requests. That doesn’t mean you might not find someone who’s sending a POST request…

For the second question, I don’t have enough context to answer. What plugin are you using? Can you post more code? Are you looking at the server side or the app/client side?

Rob

ok so i actually found this on the Supersonic developer site.

// get the variables $userId = $\_GET['applicationUserId']; $eventId = $\_GET['eventId']; $rewards = $\_GET['rewards']; $signature = $\_GET['signature']; $timestamp = $\_GET['timestamp']; $privateKey = ‘[YOUR\_PRIVATE\_KEY]’; // validate the call using the signature if (md5($timestamp.$eventId.$userId.$rewards.$privateKey) != $signature) { echo "Signature doesn’t match parameters"; return; } // check that we haven't processed the same event before if (!alreadyProcessed($eventId)){ // grant the rewards doProcessEvent($eventId, $userId, $rewards); } // return ok echo $eventId.":OK";

The following PHP code sample demonstrates a typical commission event callback handler. All you need to do after copying the code is to implement the alreadyProcessed() and doProcessEvent()functions and set the [YOUR_PRIVATE_KEY] string to the correct value.

Now im trying to implement this but cant really get it going…

So basically you need to write two functions to complete that script. The function alreadyProcessed() takes the value in $eventId and determines if you already processed this event. It needs to return either true or false for the if statement to work.

Then you need a function called doProcessEvent(…) that actually adds the event to however you’re going to track things.

Supersonic can’t be more specific. They don’t know anything about what kind of database you are using. They don’t have any ideas about how your database is structured. The only assumption they have about your data model is you can look up records by whatever value they use for $eventId.

I don’t know how SQL friendly you are or how much PHP/MySQL you know, but “alreadyProcessed” just needs to query your database (and again I can’t make assumptions about your setup) similar to:

$query = “SELECT * FROM yourdata WHERE eventId=’” . $eventId . “’”;

you would then query your database (assuming you have a database column named eventid…). Then you would check the result of the query and if it returned data (i.e. it found a row with that eventId) then you would return true if you got nothing back you would return 0.

Then the other function would add a record to the database. You would use an “INSERT INTO tablename” type query to insert the record. At this point things get really abstract, but at a minimum you would need a database table that has an auto-incrementing integer index field. You would need string type fields for each of the variables they provide, though rewards might be a number type field. I’d need to see the values to make sure.

And that would take care of their call back needs.

Rob

@Rob

Ok so this is what i have so far…

\<?php $username = 'root'; $password = ''; $database = 'test'; mysql\_connect(localhost,$username,$password); @mysql\_select\_db($database) or die( "Unable to select database"); // get the variables $userId = $\_GET['userId']; $eventId = $\_GET['eventId']; $rewards = $\_GET['rewards']; $signature = $\_GET['signature']; $timestamp = $\_GET['timestamp']; function alreadyProcessed($eventId){ $query = "SELECT \* FROM reward WHERE EVENT\_ID='" . $eventId . "'"; $result = mysql\_query($query); while($row = mysql\_fetch\_assoc($result)) { print\_r($row); } return true; } function doProcessEvent(){ } // validate the call using the signature if (md5($timestamp.$eventId.$userId.$rewards) != $signature) { echo "Signature doesnt match parameters"; return; } // check that we haven't processed the same event before if (!alreadyProcessed($eventId)){ // grant the rewards doProcessEvent($eventId, $userId, $rewards); } // return ok echo $eventId.":OK";

but if I test this I get:

_ Signature doesn’t match parameters _

How do I pass the correct eventId to the IF statement?

If i change the IF statement code to

if (md5($timestamp.$eventId.$userId.$rewards) != md5($signature))

The test returns

:OK

Please I feel like im getting lose lol

PS:

This is Supersonics test callback form

[sharedmedia=core:attachments:5518]

Not sure if im doing this right either.

The value on their callback URL certainly looks like it’s already MD5 hashed. I would suggest putting in some echo statements and echo $signature and the md5(…) results and see what they are. It probably wouldn’t hurt to also echo out all of the $_GET[] parameters you’re receiving.

You can take their URL and put it in a web browser and see what’s  happening. I’m a bit confused by the URL you have though. I don’t think they can call “localhost.com/test/test.php” from their server to hit  your server.

Rob

This may seem like a strange answer, but if you go to the Peanut Labs plugin documentation. There is a Server Requirements link there. PL requires this callback, most other ad providers its optional. But we provide a PHP/MySQL database script for their server to call to your server and record the data they have to share. There is a second script that your app would call to get the reward from your server and an example MySQL table create command.

Now the examples won’t run out of the box for Supersonic or any one other than PL since it has code to validate PL’s way of validating the callback and PL specific fields. But it should give you a starting point and a little bit of an explaination of the process that might get you further along.

Rob

@Rob

So, is the callback a GET or a POST?

Also, When I set the parameters, will it look like this?

params.rewards = '[REWARDS]'

im a little confused on how they are sending back the response…

Most callbacks that I’ve seen pass the key-value pairs as part of the URL, which would make them GET requests. That doesn’t mean you might not find someone who’s sending a POST request…

For the second question, I don’t have enough context to answer. What plugin are you using? Can you post more code? Are you looking at the server side or the app/client side?

Rob

ok so i actually found this on the Supersonic developer site.

// get the variables $userId = $\_GET['applicationUserId']; $eventId = $\_GET['eventId']; $rewards = $\_GET['rewards']; $signature = $\_GET['signature']; $timestamp = $\_GET['timestamp']; $privateKey = ‘[YOUR\_PRIVATE\_KEY]’; // validate the call using the signature if (md5($timestamp.$eventId.$userId.$rewards.$privateKey) != $signature) { echo "Signature doesn’t match parameters"; return; } // check that we haven't processed the same event before if (!alreadyProcessed($eventId)){ // grant the rewards doProcessEvent($eventId, $userId, $rewards); } // return ok echo $eventId.":OK";

The following PHP code sample demonstrates a typical commission event callback handler. All you need to do after copying the code is to implement the alreadyProcessed() and doProcessEvent()functions and set the [YOUR_PRIVATE_KEY] string to the correct value.

Now im trying to implement this but cant really get it going…

So basically you need to write two functions to complete that script. The function alreadyProcessed() takes the value in $eventId and determines if you already processed this event. It needs to return either true or false for the if statement to work.

Then you need a function called doProcessEvent(…) that actually adds the event to however you’re going to track things.

Supersonic can’t be more specific. They don’t know anything about what kind of database you are using. They don’t have any ideas about how your database is structured. The only assumption they have about your data model is you can look up records by whatever value they use for $eventId.

I don’t know how SQL friendly you are or how much PHP/MySQL you know, but “alreadyProcessed” just needs to query your database (and again I can’t make assumptions about your setup) similar to:

$query = “SELECT * FROM yourdata WHERE eventId=’” . $eventId . “’”;

you would then query your database (assuming you have a database column named eventid…). Then you would check the result of the query and if it returned data (i.e. it found a row with that eventId) then you would return true if you got nothing back you would return 0.

Then the other function would add a record to the database. You would use an “INSERT INTO tablename” type query to insert the record. At this point things get really abstract, but at a minimum you would need a database table that has an auto-incrementing integer index field. You would need string type fields for each of the variables they provide, though rewards might be a number type field. I’d need to see the values to make sure.

And that would take care of their call back needs.

Rob

@Rob

Ok so this is what i have so far…

\<?php $username = 'root'; $password = ''; $database = 'test'; mysql\_connect(localhost,$username,$password); @mysql\_select\_db($database) or die( "Unable to select database"); // get the variables $userId = $\_GET['userId']; $eventId = $\_GET['eventId']; $rewards = $\_GET['rewards']; $signature = $\_GET['signature']; $timestamp = $\_GET['timestamp']; function alreadyProcessed($eventId){ $query = "SELECT \* FROM reward WHERE EVENT\_ID='" . $eventId . "'"; $result = mysql\_query($query); while($row = mysql\_fetch\_assoc($result)) { print\_r($row); } return true; } function doProcessEvent(){ } // validate the call using the signature if (md5($timestamp.$eventId.$userId.$rewards) != $signature) { echo "Signature doesnt match parameters"; return; } // check that we haven't processed the same event before if (!alreadyProcessed($eventId)){ // grant the rewards doProcessEvent($eventId, $userId, $rewards); } // return ok echo $eventId.":OK";

but if I test this I get:

_ Signature doesn’t match parameters _

How do I pass the correct eventId to the IF statement?

If i change the IF statement code to

if (md5($timestamp.$eventId.$userId.$rewards) != md5($signature))

The test returns

:OK

Please I feel like im getting lose lol

PS:

This is Supersonics test callback form

[sharedmedia=core:attachments:5518]

Not sure if im doing this right either.

The value on their callback URL certainly looks like it’s already MD5 hashed. I would suggest putting in some echo statements and echo $signature and the md5(…) results and see what they are. It probably wouldn’t hurt to also echo out all of the $_GET[] parameters you’re receiving.

You can take their URL and put it in a web browser and see what’s  happening. I’m a bit confused by the URL you have though. I don’t think they can call “localhost.com/test/test.php” from their server to hit  your server.

Rob