h2non / youtube-video-api

Simplified programmatic and command-line interface for YouTube Video API. Built for node.js
MIT License
67 stars 16 forks source link

Cant authenticate #29

Open noushad-pp opened 7 years ago

noushad-pp commented 7 years ago

I am trying to authenticate to fetch a list of youtube videos. Which is not working.

var Youtube = require('youtube-video-api');
var youtube = Youtube({
    video: {
        part: 'status,snippet'
    },
    email: Config.EMAIL,
    password: Config.PASS
});

getVideosBySearch = function (query, callback) {
    if (!query.search_key || !query.search_key.trim()) {
        callback(true, { message: "Search query missing!" });
        return;
    }
    var queryString = {
        maxResults: 50,
        part: 'snippet',
        q: query.search_key,
        type: query.search_type //channel, video, playlist or null for all
    };

    youtube.authenticate(Config.GOOGLE_CLIENT_ID, Config.GOOGLE_CLIENT_SECRET, function (err, tokens) {
        console.log(err);
        if (err) {
            console.log(err);
            callback(false, { message: 'Authentication Failed' });
        } else {
            youtube.list(queryString, function (err, videos) {
                console.log(queryString, err, videos);
            });
        }
    })

    youtube.on('auth:success', function (err) {
        console.log(err);
    })
};

Errors are

Error: Cannot retrieve the token. Timeout exceeded
    at Timeout._onTimeout (path/node_modules/youtube-video-api/node_modules/nightmare-google-oauth2/index.js:179:18)
    at ontimeout (timers.js:386:14)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)

and

TypeError: youtube.on is not a function
    at Object.getVideosBySearch (backend/models/thirdpartyApps/youtube.js:39:10)
eladcandroid commented 5 years ago

I'm getting the same error.. Can you look at this issue?

capezzbr commented 4 years ago

Experiencing the same issue, have you guys found a solution?

ThibaultJanBeyer commented 4 years ago

Same issue…

h2non commented 4 years ago

The problem relies on this package: https://github.com/h2non/nightmare-google-oauth2

The implementation uses a sort of weak scraping mechanism, which is easy to break if Google changes their web markup implementation details.

I'm no longer supporting that package and I encourage you to use a more API driven OAuth2 token retrieval instead of web scraping.