基本上我需要获取给定repo的标签并将结果放在php数组中
我见过github API; returning an array of tags,但我对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位
答案 0 :(得分:1)
您可以使用json_decode
函数解码对关联数组的响应,并将关联传递为true
$resonse_array = json_decode($content, true);