php - 如何制作脚本以从JSON API捕获某些数据?

标签 php jquery json api app-store

我正在尝试构建一个小脚本,让我做到这一点:

http://example.com/appicons.php?id=284417350

然后以纯文本显示
http://a3.mzstatic.com/us/r1000/005/Purple/2c/a0/b7/mzl.msucaqmg.png

这是获取该信息的API查询(artworkUrl512):

http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=284417350

任何帮助和示例代码将不胜感激!

最佳答案

我不确定为什么您的标记中包含jQuery,除非您想动态地发出请求而不刷新页面。但是,您可以使用以下示例在PHP中简单地做到这一点:

$request            = array (
    "app_id"        => @$_GET["id"]
);
// parse the requests.
if (empty($request["app_id"])) {
    // redirects back / displays error
}
else {
    $app_uri    = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=" . $request["app_id"];
    $data       = file_get_contents ($app_uri);
    $json       = json_decode (trim($data));
    print($json->results[0]->artworkUrl100);
}

关于php - 如何制作脚本以从JSON API捕获某些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6904240/

相关文章:

php - 尝试使用 php 从存储在 phpmyadmin 中的数据库中选择数据时出错

php - Docker php :5. 6-apache 403(因为路径的某个组件缺少搜索权限)

php - in_array vs strpos 在 php 中的性能

php - 检查 PHP session 是否已经开始

jquery - 打开div onclick并关闭其他

javascript - 在node.js中检索JSON数据时出错

javascript - 带有 JSON 日期的 D3 v4 折线图

javascript - 如何在 Javascript/Jquery 中使用 'Value' 从 json 获取 'Key'

jquery - 使用 jTable-JQuery 进行动态删除操作

javascript - jQuery:以最佳方式根据 URL 添加类