我有网站iOS Cookies,我将用Swift编写的库(目前为190)划分为不同的类别。显示类别时,我显示了包含GitHub星号和描述数量的库的列表。
由于这些星星的数量并不准确,我决定立即通过CRON工作(每天一次)为每个图书馆获取它。问题是我因某种原因达到API限制:
您已达到GitHub小时限制!实际限制为:5000
这很奇怪,因为它不到200个库,而且每个库只调用一次,如下所示:
// GitHub API
$this->github = new GitHub($page);
// list of libraries stored in .yaml file
$libraries = $this->config->get('plugins.swift-version.libraries');
$arrlength = count($libraries);
$array = Array();
for($x = 0; $x < $arrlength; $x++) {
$link = $libraries[$x]['link'];
$path = parse_url($link, PHP_URL_PATH);
$segments = explode('/', $path);
$author = $segments[1];
$repo = $segments[2];
// actual API calling to get number of stars for library
$libraries[$x]['stargazers_count'] = $this->github->client->api('repo')->show($author, $repo)['stargazers_count'];
}
我错过了什么吗?
答案 0 :(得分:1)
为了省去编写完整的API客户端的麻烦,还因为该客户端在我的待办事项列表中,所以我还是需要试用github API,这是一个快速而肮脏的例子,它只使用了一个API请求:
$url = "https://api.github.com/repos/realm/realm-cocoa";
$token = /* https://github.com/settings/tokens */;
$headers = [
'Authorization: token ' . $token,
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
]);
$foo = json_decode(curl_exec($ch), true);
curl_close($ch);
var_dump($foo['description'], $foo['stargazers_count']);
输出:
string(64) "Realm is a mobile database: a replacement for Core Data & SQLite"
int(5888)