如何获取最新提交日期-Github API

问题描述:

我目前正在编写一个git reps的小型数据库,我想知道如果数据库中列出了代表,我将如何继续并获取最新提交的日期.

I'm currently writing a small database of git reps and im wondering how i would go ahead and get the date of the latest commit if i have the rep listed in my database.

我从来没有使用过github API,并且我很难把它包起来.

I've never worked with the github API and im having a bit of a hard time wrapping my head around it.

如果有人可以帮助我解决问题,我将非常感激.我最好找到PHP或JS,因为我发现的所有示例都是在ruby中.

If anyone could help me figure it out i'd much appreciate it. PHP or JS prefereably as all the examples ive found has been in ruby.

如果您要像 cURL 而不是 file_get_contents ,因为您需要配置

If you were to use PHP like your example, I'd use cURL instead of file_get_contents, as you'd need to configure allow-url-fopen.

GitHub还要求您在标头中发送user-agent: https: //developer.github.com/v3/#user-agent-required

GitHub also requires you to send a user-agent in the header: https://developer.github.com/v3/#user-agent-required

例如,您的PHP代码如下所示:

For example, your PHP code would look like;

$objCurl = curl_init();

//The repo we want to get
curl_setopt($objCurl, CURLOPT_URL, "https://api.github.com/repos/google/blueprint/commits");

//To comply with https://developer.github.com/v3/#user-agent-required
curl_setopt($objCurl, CURLOPT_USERAGENT, "*-29845346"); 

//Skip verification (kinda insecure)
curl_setopt($objCurl, CURLOPT_SSL_VERIFYPEER, false);

//Get the response
$response = curl_exec($objCurl);
print_r( json_decode($response, true) );

注意::您将能够继续使用file_get_contents并发送user-agent标头.参见此答案

Note: You will be able to continue using file_get_contents and send the user-agent header. See this answer