aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Amoush <mohammad_amoush@brown.edu>2019-06-26 17:54:16 -0400
committerMohammad Amoush <mohammad_amoush@brown.edu>2019-06-26 17:54:16 -0400
commit530f38e60d6289a221a463ba36af2ed22c15d8d2 (patch)
treee26f8cb27b0d3920196bbe8899650e5dd85e971b
parentb86050edd2da3acca258f117e8350aa8d53272d9 (diff)
Video Search Sample
-rw-r--r--src/client/DocServer.ts4
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx1
-rw-r--r--src/server/Message.ts2
-rw-r--r--src/server/index.ts2
-rw-r--r--src/server/youtubeApi/youtubeApiSample.js25
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