Код: Выделить всё
{
"message":"Not Found",
"documentation_url":"https://docs.github.com/rest",
"status":"404"
}
Код: Выделить всё
$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);
Когда я обрезал строку:
Код: Выделить всё
"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.
Что такое Я делаю неправильно?
Спасибо
Майк
ОБНОВЛЕНИЕ ПОСТ
Я исправил код . Но теперь я получаю такую ошибку:
Код: Выделить всё
{
"message":"Not Found",
"documentation_url":"https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user",
"status":"404"
}
Код: Выделить всё
Route::get('/route1', function () {
if (Session::get('authorization') == '1') {
Session::put('authorization', '2');
$code = request()->input('code');
if (!$code) {
return abort(404);
}
$res = Http::post('https://github.com/login/oauth/access_token', [
'client_id' => 'MY_CLIENT_ID',
'client_secret' => 'MY_SECRET',
'code' => $code,
'redirect_uri' => 'https://MY_URL/route1',
]);
$query_str = $res->body();
$data = [];
parse_str($query_str, $data);
Session::forget('authorization');
if (!isset($data['access_token'])) {
return abort(404);
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.github.com/user/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 {$data['access_token']}",
"X-GitHub-Api-Version: 2022-11-28",
"User-Agent: TryfonEuAuth"
),
CURLOPT_POSTFIELDS => array(
"name" => "my-new-repo-name",
"description" => "This is your first repo!",
"homepage" => "https://MY_HOMEPAGE",
"private" => true,
"is_template" => true
),
));
$response = curl_exec($curl);
curl_close($curl);
Log::info("aa", [$response]);
dd($response);
}
});
Route::get('/oauth', function () {
Session::put('authorization', '1');
return redirect('https://github.com/login/oauth/authorize?client_id=MY_CLIENT&state=MY_HASH');
})->middleware('auth.basic');
Подробнее здесь: https://stackoverflow.com/questions/792 ... ub-user-re