2016-12-24 202 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