Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
MagnificRogue committed Jul 7, 2018
1 parent 427d7bb commit e358219
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cors": "^2.8.3",
"dataloader": "^1.3.0",
"debug": "~2.6.0",
"dotenv": "^6.0.0",
"elasticsearch": "^13.2.0",
"express": "~4.14.1",
"express-graphql": "^0.6.3",
Expand Down
44 changes: 30 additions & 14 deletions src/api/youtubeAPI.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
var Promise = require('promise');
var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2();

function youtubeAPI(tokens, resolveName, id, args){

oauth2Client.setCredentials({
access_token:'',
refresh_token:''
//expiry_date: true
});
var oauth2Client = new OAuth2(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.CALLBACK
);

function youtubeAPI(context, resolveName, id, args){

let authorization = JSON.parse(context.headers.authorization)

var youtube = google.youtube({
version: 'v3',
auth:oauth2Client
});

return new Promise((resolve,reject) =>{

let unauthorized = !authorization || !authorization.accessToken
|| !authorization.refreshToken;


if (unauthorized) {
reject(new Error('Unauthorized Request'));
}


oauth2Client.setCredentials({
access_token: authorization.accessToken,
refresh_token: authorization.refreshToken
//expiry_date: true
});

var youtube = google.youtube({
version: 'v3',
auth:oauth2Client
});


switch(resolveName){
case 'search':
Expand All @@ -34,7 +51,6 @@ function youtubeAPI(tokens, resolveName, id, args){
console.log(error);
reject(error);
}else{
//console.log(data);
resolve(data.items);
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/server/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
require('dotenv').config();
const cors = require('cors');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const youtubeSchema = require('../schema');
const logger = require('morgan');


if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET || !process.env.CALLBACK) {
console.error('Error, Environment is missing a CLIENT_KEY, CLIENT_SECRET, and CALLBACK necessary to access the Twitter API');
process.exit(1);
}

const app = express()

app.use(cors());
Expand Down

0 comments on commit e358219

Please sign in to comment.