我正在使用这个帮助库PHPLeague Github OAuth2来检索组织的存储库列表。我已经添加了per_page=100
参数,但仍然有100多个,所以我需要使用分页。根据API文档,有一个Link头,但我不确定这个库是否真的支持分页结果。我在Guzzle文档中看到有一个$response->getHeader('name')
方法,但在库响应中使用它时似乎没有返回任何内容。
/**
* Retrieve list of organization repos from Github API.
* https://developer.github.com/v3/repos/#list-organization-repositories
*
* @return mixed|'WP_Error
*/
public function get_repos() {
$plugin_options = Settings::get_instance()->get_settings();
if ( empty( $plugin_options['github_token'] ) ) {
return new 'WP_Error( 'not authenticated' );
}
$provider = GithubAuth::get_instance()->get_provider();
$request = $provider->getAuthenticatedRequest(
'GET',
GithubAuth::get_instance()->get_api_url() . '/orgs/myorg/repos?per_page=100',
$plugin_options['github_token']
);
$response = $provider->getResponse( $request );
// HERE CHECK IF THERE ARE MORE RESULTS
return $response;
}
库作者在此处回答https://github.com/thephpleague/oauth2-github/issues/6#issuecomment-234537057