-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalSelectVideo.js
More file actions
86 lines (68 loc) · 2.29 KB
/
ModalSelectVideo.js
File metadata and controls
86 lines (68 loc) · 2.29 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
function init() {
window.initGapi(); // Calls the init function defined on the window
}
angular.module('ActionDriveApp')
.controller('ModalSelectVideo', ['$scope', '$uibModalInstance', '$window',SelectSpotListController]);
function SelectSpotListController($scope, $uibModalInstance, $window) {
var OAUTH2_CLIENT_ID = '846999749838-g0klmeg5mhemmrdb2hr1nllludp2o1qb.apps.googleusercontent.com';
var OAUTH2_SCOPES = [
'https://www.googleapis.com/auth/youtube'
];
$scope.youtubeVideos = [];
$window.initGapi = function () {
gapi.auth.init(function () {
window.setTimeout(checkAuth, 1);
});
};
function checkAuth() {
gapi.auth.authorize({
client_id: OAUTH2_CLIENT_ID,
scope: OAUTH2_SCOPES,
immediate: true
}).then(function (response) {
handleAuthResult(response);
});
}
var handleAuthResult = function (authResult) {
if (authResult && !authResult.error) {
loadAPIClientInterfaces();
} else {
}
}
var loadAPIClientInterfaces = function () {
gapi.client.load('youtube', 'v3', function () {
requestUserUploadsPlaylistId();
});
}
var requestUserUploadsPlaylistId = function () {
var request = gapi.client.youtube.channels.list({
mine: true,
part: 'contentDetails'
});
request.execute(function (response) {
requestVideoPlaylist(response.result.items[0].contentDetails.relatedPlaylists.uploads);
});
}
var requestVideoPlaylist = function (playlistId, pageToken) {
var requestOptions = {
playlistId: playlistId,
part: 'snippet',
maxResults: 10
};
if (pageToken) {
requestOptions.pageToken = pageToken;
}
var request = gapi.client.youtube.playlistItems.list(requestOptions);
request.execute(function (response) {
$scope.youtubeVideos = response.items;
angular.element('#mybutton').triggerHandler('click');
});
}
$scope.ok = function () {
$uibModalInstance.close(selected);
};
$scope.cancel = function () {
$uibModalInstance.dismiss();
};
}