-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
118 lines (78 loc) · 2.92 KB
/
home.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
require_once 'Global.php';
$inst1 = UserFactory::Instance();
$client = $inst1->client;
$yt = $inst1->youtube;
$htmlBody = file_get_contents('content.html');
// Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
// This code executes if the user ays tenters an action in the form
// and submits the form. Otherwise, the page displhe form above.
if($client->isAccessTokenExpired()) {
echo "Token expired ";
}
if (isset($_GET['videoId']) && $_GET['videoId']) {
//get list video Id
$fullDate = $dateValue."T".$timeValue.":00.50Z";
try {
$pieces = explode(",", $videoId);
foreach ($pieces as $key => $value) {
# code...
// echo $value;
setVideoTime($yt, $value, $fullDate , $htmlBody);
}
} catch (Google_Service_Exception $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
}
$_SESSION['token'] = $client->getAccessToken();
} else {
// If the user hasn't authorized the app, initiate the OAuth flow
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$htmlBody = <<<END
<h3>Authorization Required</h3>
<p>You need to <a href="$authUrl">authorize access</a> before proceeding.<p>
END;
}
/**
* Returns a list of metadata for a video.
*
*/
// set public time
function setVideoTime(Google_Service_YouTube $youtube, $videoId, $publicDate, &$htmlBody) {
// Call the YouTube Data API's videos.list method to retrieve videos.
// Call the API's videos.list method to retrieve the video resource.
$listResponse = $youtube->videos->listVideos("status", array('id'=>$videoId));
# array( 'id' => $VIDEO_ID, 'status' => array('privacyStatus' => 'public')));
// If $listResponse is empty, the specified video was not found.
if (empty($listResponse)) {
$htmlBody .= sprintf('<h3>Can\'t find a video with video id: %s</h3>', $videoId);
} else {
// Since the request specified a video ID, the response only
// contains one video resource.
$video = $listResponse[0];
$videoStatus = $video['status'];
$videoStatus->privacyStatus = 'private'; #privacyStatus options are public, private, and unlisted
$videoStatus->publishAt = $publicDate;//'2016-11-23T07:29:00.50Z';
$video->setStatus($videoStatus);
$updateResponse = $youtube->videos->update('status', $video);
$htmlBody .= sprintf('<li> Update success for id: %s </li>', $updateResponse['id']);
$htmlBody .= '</ul>';
}
}
?>
<!doctype html>
<html>
<head>
<title>Set and retrieve localized metadata for a video</title>
</head>
<body>
<?=$htmlBody?>
</body>