从城市飞艇中抓取设备令牌

时间:2014-11-12 08:52:32

标签: php curl push-notification urbanairship.com

如果有人正在离开Urban Airship,因为他们正在使他们的自由推送系统落地,毫无疑问你想从他们的服务器中获取设备令牌。如果是这样的话,希望这会对你有帮助......

2 个答案:

答案 0 :(得分:2)

 <?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.

 }

?>

答案 1 :(得分:0)