-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05demo-request-method.php
More file actions
46 lines (31 loc) · 1.13 KB
/
05demo-request-method.php
File metadata and controls
46 lines (31 loc) · 1.13 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
46
<?php
/**
* This program demonstrates the use of github api
*/
//using curl for api call
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, );
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//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/user/starred/httpie/cli',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_USERAGENT => "pdas544", // GitHub API requires a user agent
CURLOPT_CUSTOMREQUEST => 'PUT', // Specify the request method
]);
// 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);
// Output the response and status code
//404 : means this repo is not starred by the user
echo "HTTP Status Code: " . $statusCode . "<br/>";
echo $response . "<br/>";