-1

基本上我需要获取给定 repo 的标签并将结果放在 php 数组中

我看过github API;返回一组标签,但我没有使用 cURL 的经验。

我认为网址是https://api.github.com/repos/joshf/MYREPO/git/refs/tag但我不确定如何将答案放入数组中

我找到了 GitHub API v2 的指南,但没有找到 v3

任何帮助,将不胜感激

编辑:

<?php


$url = "https://api.github.com/repos/joshf/Burden/git/refs/tags";
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "test");
$r=curl_exec($ch);
curl_close($ch);

echo $r;

$response_array = json_decode($r, true);
echo $response_array->{"ref"};

?>

给我

[{"ref":"refs/tags/1.2","url":"https://api.github.com/repos/joshf/Burden/git/refs/tags/1.2","object":{"sha":"d04eabe44b52e65ca2e1c1eaaca4321195d85001","type":"tag","url":"https://api.github.com/repos/joshf/Burden/git/tags/d04eabe44b52e65ca2e1c1eaaca4321195d85001"}},{"ref":"refs/tags/1.3","url":"https://api.github.com/repos/joshf/Burden/git/refs/tags/1.3","object":{"sha":"74d40e3f89717cbadc11e23e8ab4350d85deb015","type":"tag","url":"https://api.github.com/repos/joshf/Burden/git/tags/74d40e3f89717cbadc11e23e8ab4350d85deb015"}}]

我想要的只是标签的 1.2 和 1.3 位

4

1 回答 1

1

您可以使用json_decode函数解码对关联数组的响应,将关联传递为true

 $resonse_array = json_decode($content, true);
于 2013-05-19T11:08:52.790 回答