Grabbing Device Tokens from Urban Airship

137 views Asked by At

If anyone is moving away from Urban Airship as they are sunsetting their free push system, no doubt you would like to grab the device tokens from their server. If that's the case, hopefully this will help you...

2

There are 2 answers

0
JapanDev On BEST ANSWER
 <?php

$appKey = '<Your App Key>';
$appSecret = '<Your App Master Secret>';

$fetchedDeviceTokens = array();

$url = "https://go.urbanairship.com/api/device_tokens/";

for ($x=0; $x<=100000; $x++) {

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
    curl_setopt($curl, CURLOPT_POST, false);
    curl_setopt($curl, CURLOPT_USERPWD, $appKey .":".$appSecret); 

    $json_response = curl_exec($curl);

    $res = json_decode($json_response);
    $nextURL = $res->next_page;   

    $deviceTokensObjectArray = $res->device_tokens;

    foreach($deviceTokensObjectArray as $val){
        $deviceToken = $val->device_token;
        $fetchedDeviceTokens[] = $deviceToken;
    }

    if($nextURL){
        $url = $nextURL;
    }
    else{
        break;
    }    
} 

foreach($fetchedDeviceTokens as $val){

//USE THIS LOOP TO INSERT INTO YOR DATABASE OR CREATE AN XML ETC.

 }

?>
0
FallDi On