Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

not able to connect with google API

Hi I'm trying to connect with the youtube API and the first step needed is to get an OAuth2.0 access token.

however I keep on getting the following error: status code: 400 Error: invalid_request Required parameter is missing: response_type

Im using NodeJS and my code is

const https = require('https'); var querystring = require('querystring'); var fs = require('fs'); var clientId = "*************************************.apps.googleusercontent.com";

module.exports.authorizeYoutubeAccount = function(){ // Build the post string from an object var getData = querystring.stringify({ 'client_id': clientId, 'redirect_uri': 'http://localhost:3000/oauth2callback', 'response_type': 'code', 'scope': 'https://www.googleapis.com/auth/youtube.readonly', 'access_type': 'offline' });

console.log("data: " + getData);

var getOptions = {
    hostname: 'accounts.google.com',
    port: 443,
    path: '/o/oauth2/auth',
    method: 'GET'
};

var req = https.request(getOptions, function (res) {
    console.log('statusCode: ', res.statusCode);
    if (res.statusCode != 200) {
        console.log("error");
    }
    console.log('headers: ', res.headers);
    res.on('data', function (chunk) {
        console.log('Response: ' + chunk);
    }).on('error', function (err) {
        console.error(err);
    });
});
// post the data
req.write(getData);
req.end();

}