-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04github-api.php
More file actions
47 lines (31 loc) · 1.21 KB
/
04github-api.php
File metadata and controls
47 lines (31 loc) · 1.21 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
47
<?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);
//set headers
$headers = [
"Authorization: Bearer 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",
];
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.github.com/user/starred/firebase/php-jwt',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_USERAGENT => 'php-curl', // 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);
//checking the content type and content length from the response headers
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$contentLength = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
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/>";