Created
January 15, 2017 16:38
-
-
Save travstoll/6c5d40a44ec847a249cc7672a726b7a3 to your computer and use it in GitHub Desktop.
View GitHub Repos in PHP with File_Get_Contents using GitHub API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//post url | |
$url = "https://api.github.com/users/octocat/repos"; | |
//set file_get_contents header info | |
$opts = [ | |
'http' => [ | |
'method' => 'GET', | |
'header' => [ | |
'User-Agent: PHP', | |
'Content-type: application/x-www-form-urlencoded' | |
] | |
] | |
]; | |
//initiate file_get_contents | |
$context = stream_context_create($opts); | |
//make request | |
$content = file_get_contents($url, false, $context); | |
//decode response to array | |
$response_array = json_decode($content, true); | |
var_dump($response_array); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment