前言
在阅读本文章之前,请确保您已经阅读【App Store Connect API ( 1 ) 】获取请求 API 的 Token
通常,开发者需要打开并登录到 Apple Developer
网站才能进行设备添加操作。
而使用 App Store Connect API
,不仅可以提高开发者的工作效率,还可以实现自动化签名部署。
请求 API
在 Apple开发者网站 提供的文档内,我们可以知道以下信息:
- 请求类型:GET
- 请求URL:https://api.appstoreconnect.apple.com/v1/devices
- 请求参数:详见Apple开发者文档
本文无特殊需求,仅需要添加参数 limit=200
来设置返回的设备数量。本文使用 PHP
语言调用 API。
检查输入的参数
if(empty($_GET['token'])){
$result = array(
'status' => '409',
'detail' => '$token is required'
);
echo json_encode($result);
exit();
}
初始化并设置CURL函数
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.appstoreconnect.apple.com/v1/devices?fields[devices]=udid&limit=200',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$_GET['token']
),
));
调用CURL函数和关闭CURL进程
$response = curl_exec($curl);
curl_close($curl);
输出返回结果并结束进程
echo $response;
exit();
完整代码
<?php
error_reporting(0);
if(empty($_GET['token'])){
$result = array(
'status' => '409',
'detail' => '$token is required'
);
echo json_encode($result);
exit();
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.appstoreconnect.apple.com/v1/devices?fields[devices]=udid&limit=200',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$_GET['token']
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
exit();
评论 (0)