Answer the question
In order to leave comments, you need to log in
How to parse Github API in PHP?
Hello. I'm trying to display a list of repository releases on the site through the Github API.
$url = 'https://api.github.com/repos/modxcms/revolution/tags';
$json = file_get_contents($url);
$releases = json_decode($json);
echo '<pre>';
var_dump($releases);
echo '</pre>';
<?php
$url = 'https://api.github.com/repos/modxcms/revolution/tags';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'User-Agent: https://api.github.com/meta'
));
$result = curl_exec($cURL);
curl_close($cURL);
$json = json_decode($result, true);
//print_r($json);
Answer the question
In order to leave comments, you need to log in
Missing 'User-Agent' header
You can do this:
<?
$context = stream_context_create([
'http' => [
'header' => 'User-Agent: Awesome-Octocat-App'
]
]);
$url = 'https://api.github.com/repos/modxcms/revolution/tags';
$json = file_get_contents($url, false, $context);
$releases = json_decode($json, true);
echo '<pre>';
var_dump($releases);
echo '</pre>';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question