如何使用php-ccurl(带凭据)从github获取发布信息


How to get releases information from github using php-curl (with credentials)?

我可以使用curl获取github发布的详细信息,但我想使用php来实现这一点。

我在curl中使用的命令如下:

curl -u user.ca:password -X GET https://api.github.com/repos/xyz/abc/releases

相当于-u选项的php是CURLOPT_USERPWD

curl_setopt($ch, CURLOPT_USERPWD, 'user.ca:password');

最后你会得到这样的东西:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/xyz/abc/releases"); 
curl_setopt($ch, CURLOPT_USERPWD, 'user.ca:password');
curl_setopt($ch, CURLOPT_USERAGENT,'Awesome-Octocat-App');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$fetch = curl_exec($ch); 
curl_close($ch);