前言
在阅读本文章之前,请确保您已经阅读【App Store Connect API ( 1 ) 】获取请求 API 的 Token
通常,我们需要到 App Store Connect
网页才能够管理自己的App。
而现在,通过调用 App Store Connect API
也能实现管理账号内的App,本文讲解列出账户下的所有App。
请求 API
在 Apple开发者网站
提供的文档内,我们可以知道以下信息:
- 请求方式:GET
- 请求URL:https://api.appstoreconnect.apple.com/v1/apps
- 请求参数及其要求:详见Apple开发者文档
无特殊需求,本功能的实现无需添加额外参数。实现本功能仅需生成的 Token
即可。
PHP参考代码如下。
<?php
error_reporting(0);
//如果没有Token则抛出错误并停止运行
if(empty($_GET['token'])){
$result = array(
'status' => '409',
'detail' => '$token is required'
);
echo json_encode($result);
exit();
}
//初始化curl请求
$curl = curl_init();
//对curl请求进行设置
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.appstoreconnect.apple.com/v1/apps',
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'] //通过$_GET['token']获取传入的token
),
));
//进行请求
$response = curl_exec($curl);
//关闭请求进程
curl_close($curl);
//停止运行
exit();
输出返回的结果
要输出结果仅需要添加下面的代码即可。
//输出返回的结果
echo $response;
全部代码(无注释)
<?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/apps',
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)