2016-12-24 166 views
1

在这里做某人知道如何使用GitHub API? 我试图做一个表检索所有的库提交(https://api.github.com/repos/RubeVi/Fenix/commits)。只想显示沙,但看起来像我的代码是错的GitHub API提交

<?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> 
+0

标签的东西正确。 –

+0

...因为你的代码中有错误的URL? – duskwuff

+0

@duskwuff很多事情发生了...伙计... –

回答

2

这是你所期待的?

preview

如果是这样,做这种方式,很容易看到还有:

<?php 
$opts = ['http' => ['method' => 'GET', 'header' => ['User-Agent: PHP']]]; 
$context = stream_context_create($opts); 
$json = file_get_contents("https://api.github.com/repos/RubeVi/Fenix/commits", false, $context); 
$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> 

上的使用问题:file_get_contents() gets 403 from api.github.com everytime