diff options
-rw-r--r-- | src/client/DocServer.ts | 4 | ||||
-rw-r--r-- | src/client/apis/youtube/YoutubeBox.tsx | 1 | ||||
-rw-r--r-- | src/server/Message.ts | 2 | ||||
-rw-r--r-- | src/server/index.ts | 2 | ||||
-rw-r--r-- | src/server/youtubeApi/youtubeApiSample.js | 25 |
5 files changed, 32 insertions, 2 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 9dae54d74..b0060bfdc 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -52,6 +52,10 @@ export namespace DocServer { return apiKey; } + export function getYoutubeVideos() { + Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, YoutubeQueryTypes.SearchVideo); + } + export async function GetRefFields(ids: string[]): Promise<{ [id: string]: Opt<RefField> }> { const requestedIds: string[] = []; diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx index b029c51ec..dce891a07 100644 --- a/src/client/apis/youtube/YoutubeBox.tsx +++ b/src/client/apis/youtube/YoutubeBox.tsx @@ -19,6 +19,7 @@ export class YoutubeBox extends React.Component<FieldViewProps> { componentWillMount() { DocServer.getYoutubeChannels(); + DocServer.getYoutubeVideos(); } _ignore = 0; diff --git a/src/server/Message.ts b/src/server/Message.ts index 0fc5dd4b5..87bb9d0fc 100644 --- a/src/server/Message.ts +++ b/src/server/Message.ts @@ -25,7 +25,7 @@ export interface Transferable { } export enum YoutubeQueryTypes { - Channels + Channels, SearchVideo } export interface Reference { diff --git a/src/server/index.ts b/src/server/index.ts index b36cb0bf2..3d4f59ee4 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -372,6 +372,8 @@ function HandleYoutubeQuery([type, callback]: [YoutubeQueryType, (result?: strin case YoutubeQueryType.Channels: YoutubeApi.authorizedGetChannel(youtubeApiKey); break; + case YoutubeQueryType.SearchVideo: + YoutubeApi.authorizedGetVideos(youtubeApiKey); } } diff --git a/src/server/youtubeApi/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js index 7d5c936f5..35d74c62f 100644 --- a/src/server/youtubeApi/youtubeApiSample.js +++ b/src/server/youtubeApi/youtubeApiSample.js @@ -23,11 +23,16 @@ module.exports.readApiKey = (callback) => { module.exports.authorizedGetChannel = (apiKey) => { //this didnt get called - console.log("I get called"); + console.log("I get called ", apiKey); + console.log(TOKEN_PATH); // Authorize a client with the loaded credentials, then call the YouTube API. authorize(JSON.parse(apiKey), getChannel); } +module.exports.authorizedGetVideos = (apiKey) => { + authorize(JSON.parse(apiKey), getSampleVideos); +} + /** * Create an OAuth2 client with the given credentials, and then execute the @@ -132,4 +137,22 @@ function getChannel(auth) { channels[0].statistics.viewCount); } }); +} + +function getSampleVideos(auth) { + let service = google.youtube('v3'); + service.search.list({ + auth: auth, + part: 'id, snippet', + type: 'video', + q: 'istanbul', + maxResults: 3 + }, function (err, response) { + if (err) { + console.log('The API returned an error: ' + err); + return; + } + let videos = response.data.items; + console.log('Videos found: ' + videos[0].id.videoId, " ", videos[0].snippet.title); + }); }
\ No newline at end of file |