我收到错误:
{
"message":"Not Found",
"documentation_url":"https://docs.github.com/rest",
"status":"404"
}
尝试在我的 GitHub 帐户上创建私人存储库时。我的 php 代码:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.github.com/MY_USERNAME/repos',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Accept: application/vnd.github+json",
"Authorization: Bearer MY_TOKEN",
"X-GitHub-Api-Version: 2022-11-28",
"User-Agent: MY_APP_NAME"
),
CURLOPT_POSTFIELDS => array(
"name" => "test-repo-123",
"description" => "This is your first repo!",
"homepage" => "https://MY_URL",
"private" => true,
"is_template" => true
),
));
$response = curl_exec($curl);
curl_close($curl);
我必须创建 GH 应用程序,并将其安装在我的 GH 帐户上。
当我剪线时:
"User-Agent: MY_APP_NAME"
我收到错误:
Request forbidden by administrative rules. Please make sure your request has a User-Agent header (https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required). Check https://developer.github.com for other possible causes.
当然,在常量中:
MY_USERNAME, MY_TOKEN, MY_APP_NAME, MY_URL
我有我的敏感数据。
我做错了什么?
谢谢 迈克
根据我的发现,您的网址不应包含“MY_USERNAME”(您的用户名),而应包含“user”一词。
// FROM
CURLOPT_URL => 'https://api.github.com/MY_USERNAME/repos',
// TO
CURLOPT_URL => 'https://api.github.com/user/repos',
这里 GitHub 为用户创建了一个管理存储库的端点,因此它就像一个占位符,可以精确地为经过身份验证的用户创建存储库。
希望这有帮助!