-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
63 lines (55 loc) · 2.15 KB
/
Copy pathmain.php
File metadata and controls
63 lines (55 loc) · 2.15 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Data API v3</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div>
<h2 class="text-center">YouTube Data API v3</h2>
<form action="main.php" method="get" name="authCode">
Enter verification code: <input type="text" name="authCode">
<input type="submit" name="submit">
</form>
<?php
require 'get_auth_url.php';
if (isset($_GET["authCode"])) {
$authCode = $_GET["authCode"];
}
$response = array();
if (isset($_GET["submit"])) {
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
// Define service object for making API requests.
$service = new Google_Service_YouTube($client);
$queryParams = [
'channelId' => 'UCxnUFZ_e7aJFw3Tm8mA7pvQ',
'maxResults' => 10,
'order' => 'date'
];
$response = $service->search->listSearch('snippet', $queryParams);
}
if(!empty($response->items)) {
foreach($response->items as $item) {
if (isset($item->id->videoId)) {
?>
<div class="col-md-auto">
<iframe width="280" height="150"
src="https://www.youtube.com/embed/<?php echo $item->id->videoId; ?>"
framebolder="0" allowfullscreen></iframe>
<h4><?php echo $item->snippet->title; ?></h4>
</div>
<?php
}
}
}
?>
</div>
</div>
</body>
</html>