-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07demo-rest.php
More file actions
45 lines (30 loc) · 1.03 KB
/
07demo-rest.php
File metadata and controls
45 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* This program demonstrates the use of github rest api
*/
//using curl for api call
$ch = curl_init();
//using classic personal access token for authentication
$headers = [
"Accept: application/vnd.github+json",
"Authorization: token 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",
"X-GitHub-Api-Version: 2022-11-28"
];
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.github.com/gists/1fd85f66e0472687e87eb10261bdb7b7',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => "pdas544", // GitHub API requires a user agent
]);
// Execute the cURL request and get the response
// This will return the response as a string instead of outputting it directly
$response = curl_exec($ch);
//get the http status code
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$response = json_decode($response, true);
print_r($response);
// foreach ($response as $gist) {
// echo "Gist ID: " . $gist['id'] . "<br/>";
// echo "Description: " . $gist['description'] . "<br/>";
// echo "<hr/>";
// }