я пытаюсь загрузить частный репозиторий Github с помощью GitHub API для моего веб-сервера.
Соединение с моим хранилищем успешно.
Но когда я пытаюсь загрузить файл, я получаю Предупреждение: file_get_contents (https://api.github.com/repos/sistecs/sisMedia/tarball/5.1): не удалось открыть поток: ошибка HTTP-запроса! HTTP / 1.1 404 не найден
Вот мой код:
$url = 'https://api.github.com/repos/sistecs/sismedia/releases/614885';
$curl_token_auth = 'Authorization: token ' . $token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: sistecs', $curl_token_auth));
$content = curl_exec($ch);
$content = json_decode($content,true);
$context = stream_context_create(array('http' => array(
'header' => 'User-Agent: sistecs',
)));
$Tarball = file_get_contents($content["tarball_url"],false, $context);
$savefile = fopen("sismedia.tar.gz", "w");
fwrite($savefile, $Tarball);
fclose($savefile);
curl_close($ch);
Вот возвращение вызова API
Array
(
[url] => https://api.github.com/repos/sistecs/sisMedia/releases/614885
[assets_url] => https://api.github.com/repos/sistecs/sisMedia/releases/614885/assets
[upload_url] => https://uploads.github.com/repos/sistecs/sisMedia/releases/614885/assets{?name}
[html_url] => https://github.com/sistecs/sisMedia/releases/tag/5.1
[id] => 614885
[tag_name] => 5.1
[target_commitish] => master
[name] => v5.1
[draft] =>
[author] => Array
(
[login] => sistecs
[id] => 6322229
[avatar_url] => https://avatars.githubusercontent.com/u/6322229?v=2
[gravatar_id] =>
[url] => https://api.github.com/users/sistecs
[html_url] => https://github.com/sistecs
[followers_url] => https://api.github.com/users/sistecs/followers
[following_url] => https://api.github.com/users/sistecs/following{/other_user}
[gists_url] => https://api.github.com/users/sistecs/gists{/gist_id}
[starred_url] => https://api.github.com/users/sistecs/starred{/owner}{/repo}
[subscriptions_url] => https://api.github.com/users/sistecs/subscriptions
[organizations_url] => https://api.github.com/users/sistecs/orgs
[repos_url] => https://api.github.com/users/sistecs/repos
[events_url] => https://api.github.com/users/sistecs/events{/privacy}
[received_events_url] => https://api.github.com/users/sistecs/received_events
[type] => User
[site_admin] =>
)
[prerelease] =>
[created_at] => 2014-10-09T14:07:32Z
[published_at] => 2014-10-09T14:23:44Z
[assets] => Array
(
)
[tarball_url] => https://api.github.com/repos/sistecs/sisMedia/tarball/5.1
[zipball_url] => https://api.github.com/repos/sistecs/sisMedia/zipball/5.1
[body] => sisMedia 5 inkl. Benutzerverwaltung
)
Может кто-нибудь мне помочь?
Это было намного проще, чем я думал.
Вот решение:
$context = stream_context_create(array('http' => array(
'header' => 'User-Agent: sistecs',
)));
$File = file_get_contents("https://api.github.com/repos/sistecs/sisMedia/tarball/5.1?access_token=MYTOKEN",false, $context);
$SaveFile = fopen("temp/sismedia.tar.gz", "w");
fwrite($SaveFile, $File);
fclose($SaveFile);
Других решений пока нет …