我刚刚开始学习如何使用GitHub API。我编写了一个示例程序,列出了我的存储库。我有5个存储库,而我只有一个。有什么想法吗?
我的代码:
<? php
DEFINE ('PERSONAL_TOKEN', 'xxxxxxxxxxxxxxxxx');
$headers = [
'Accept: application/vnd.github.v3+json',
'User-Agent: Some Text',
'Authorization: token '. PERSONAL_TOKEN
];
$res = list_repositories($headers);
print "<pre>";
print_r($res);
print "</pre>";
function list_repositories($headers)
{
$curl_url = GITHUB_REST_URL.'myusernameful'.'/repos';
$ch = curl_init($curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = json_decode(curl_exec($ch), TRUE);
curl_close($ch);
return $output;
}
我原本希望拿回我所有的5个回购单,但我只能拿回一个:
Array
(
[0] => Array
(
[id] => 168594503
[node_id] => MDEwOlJlcG9zaXRvcnkxNjg1OTQ1MDM=
[name] => repo_one
[full_name] => myusername/repo_one
[private] =>
[owner] => Array
(
[login] => myusername
[id] => 45577729
[node_id] => MDQ6VXNlcjQ1NTc3NzI5
[avatar_url] => https://avatars1.githubusercontent.com/u/45577729?v=4
[gravatar_id] =>
[url] => https://api.github.com/users/myusername
[html_url] => https://github.com/myusername
[followers_url] => https://api.github.com/users/myusername/followers
[following_url] => https://api.github.com/users/myusername/following{/other_user}
[gists_url] => https://api.github.com/users/myusername/gists{/gist_id}
[starred_url] => https://api.github.com/users/myusername/starred{/owner}{/repo}
[subscriptions_url] => https://api.github.com/users/myusername/subscriptions
[organizations_url] => https://api.github.com/users/myusername/orgs
[repos_url] => https://api.github.com/users/myusername/repos
[events_url] => https://api.github.com/users/myusername/events{/privacy}
[received_events_url] => https://api.github.com/users/myusername/received_events
[type] => User
[site_admin] =>
)
[html_url] => https://github.com/myusername/repo_one
[description] => repo_one makes it easy and fast to build beautiful mobile apps.
[fork] => 1
[url] => https://api.github.com/repos/myusername/repo_one
[forks_url] => https://api.github.com/repos/myusername/repo_one/forks
[keys_url] => https://api.github.com/repos/myusername/repo_one/keys{/key_id}
[collaborators_url] => https://api.github.com/repos/myusername/repo_one/collaborators{/collaborator}
[teams_url] => https://api.github.com/repos/myusername/repo_one/teams
[hooks_url] => https://api.github.com/repos/myusername/repo_one/hooks
[issue_events_url] => https://api.github.com/repos/myusername/repo_one/issues/events{/number}
[events_url] => https://api.github.com/repos/myusername/repo_one/events
[assignees_url] => https://api.github.com/repos/myusername/repo_one/assignees{/user}
[branches_url] => https://api.github.com/repos/myusername/repo_one/branches{/branch}
[tags_url] => https://api.github.com/repos/myusername/repo_one/tags
[blobs_url] => https://api.github.com/repos/myusername/repo_one/git/blobs{/sha}
[git_tags_url] => https://api.github.com/repos/myusername/repo_one/git/tags{/sha}
[git_refs_url] => https://api.github.com/repos/myusername/repo_one/git/refs{/sha}
[trees_url] => https://api.github.com/repos/myusername/repo_one/git/trees{/sha}
[statuses_url] => https://api.github.com/repos/myusername/repo_one/statuses/{sha}
[languages_url] => https://api.github.com/repos/myusername/repo_one/languages
[stargazers_url] => https://api.github.com/repos/myusername/repo_one/stargazers
[contributors_url] => https://api.github.com/repos/myusername/repo_one/contributors
[subscribers_url] => https://api.github.com/repos/myusername/repo_one/subscribers
[subscription_url] => https://api.github.com/repos/myusername/repo_one/subscription
[commits_url] => https://api.github.com/repos/myusername/repo_one/commits{/sha}
[git_commits_url] => https://api.github.com/repos/myusername/repo_one/git/commits{/sha}
[comments_url] => https://api.github.com/repos/myusername/repo_one/comments{/number}
[issue_comment_url] => https://api.github.com/repos/myusername/repo_one/issues/comments{/number}
[contents_url] => https://api.github.com/repos/myusername/repo_one/contents/{+path}
[compare_url] => https://api.github.com/repos/myusername/repo_one/compare/{base}...{head}
[merges_url] => https://api.github.com/repos/myusername/repo_one/merges
[archive_url] => https://api.github.com/repos/myusername/repo_one/{archive_format}{/ref}
[downloads_url] => https://api.github.com/repos/myusername/repo_one/downloads
[issues_url] => https://api.github.com/repos/myusername/repo_one/issues{/number}
[pulls_url] => https://api.github.com/repos/myusername/repo_one/pulls{/number}
[milestones_url] => https://api.github.com/repos/myusername/repo_one/milestones{/number}
[notifications_url] => https://api.github.com/repos/myusername/repo_one/notifications{?since,all,participating}
[labels_url] => https://api.github.com/repos/myusername/repo_one/labels{/name}
[releases_url] => https://api.github.com/repos/myusername/repo_one/releases{/id}
[deployments_url] => https://api.github.com/repos/myusername/repo_one/deployments
[created_at] => 2019-01-31T20:50:56Z
[updated_at] => 2019-02-01T22:17:23Z
[pushed_at] => 2019-01-31T20:48:11Z
[git_url] => git://github.com/myusername/repo_one.git
[ssh_url] => git@github.com:myusername/repo_one.git
[clone_url] => https://github.com/myusername/repo_one.git
[svn_url] => https://github.com/myusername/repo_one
[homepage] => https://repo_one.io
[size] => 52581
[stargazers_count] => 0
[watchers_count] => 0
[language] => Dart
[has_issues] =>
[has_projects] => 1
[has_downloads] => 1
[has_wiki] => 1
[has_pages] =>
[forks_count] => 0
[mirror_url] =>
[archived] =>
[open_issues_count] => 0
[license] => Array
(
[key] => other
[name] => Other
[spdx_id] => NOASSERTION
[url] =>
[node_id] => MDc6TGljZW5zZTA=
)
[forks] => 0
[open_issues] => 0
[watchers] => 0
[default_branch] => master
[permissions] => Array
(
[admin] => 1
[push] => 1
[pull] => 1
)
)
)
答案 0 :(得分:2)
“ List your Repositories”是/user/repos
,而不是/users/:username/repos
。
如果您在URL中使用GitHub用户名(在后一种情况下),则只会获得您的 public 存储库,而不会获得 all 的存储库(公共和私有) )