【发布时间】:2017-05-09 15:48:28
【问题描述】:
这里有人知道如何使用 GitHub API 吗? 我正在尝试创建一个表来检索所有存储库提交 (https://api.github.com/repos/RubeVi/Fenix/commits)。只想显示sha,但看起来我的代码是错误的
<?php
$json = file_get_contents("https://api.github.com/repos/RubeVi/Fenix/commits");
$obj = json_decode($json, true);
?>
<table>
<?php foreach ($obj as $o) { ?>
<tr>
<td><?php echo $o["sha"]; ?></td>
<td><?php echo $o["commit"]["author"]["name"]; ?></td>
<td><?php echo $o["commit"]["author"]["email"]; ?></td>
<td><?php echo $o["commit"]["message"]; ?></td>
</tr>
<?php } ?>
</table>
【问题讨论】:
-
正确标记事物。
-
...因为您的代码中有错误的 URL?
-
@duskwuff 发生了很多事情,伙计......
-
@duskwuff 很复杂
-
没有回答,需要
$opts = ['http' => ['method' => 'GET', 'header' => ['User-Agent: PHP']]]; $context = stream_context_create($opts);
标签: php json github-api