Open nikswap opened 8 years ago
Seems like Google changed the login form, so scrapping process is not working fine. Have to review it in detail.
Please review it!
Will take a look when I'm free. This kind of web scraping automation is very annoying to support since Google is trying to do it as hard as possible.
My suggestion would be to save the OAuth2 credentials from JSON file and reuse it across projects to avoid automatic web token retrieval each time.
Nice suggestion, it work fine. But could you confirm it will auto regenerate access token before it expires? Thanks!
Yes, I'll try to work on this later this week, however, the generated JSON should include a renewal token, so asking for a fresh token is not be required.
@duclvz Could you provide a sample of your working code? Thanks
The auto regenerate access token of mine didn't work, so I wrote a simple code to renew the token myself, and wrote it back to the credential file.
You can check the expires_in value of the access token from the API:
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=[Your Access Token]
So if it gets less than x secs. or already expired, just renew it.
var oauth2file = './.google-oauth2-credentials.json'; var file = require(oauth2file);
if (expires < 50 || typeof expires == 'undefined') { request({ url: 'https://accounts.google.com/o/oauth2/token', method: 'POST', form: { 'grant_type': 'refresh_token', 'refresh_token': '[Your Refresh Token]', 'client_id': '[Your Client ID]', 'client_secret': '[Your Client Secret]' } }, function(err, res) { if (err) { console.log(err); } var json = JSON.parse(res.body); oauth2file.access_token = json.access_token;
fs.writeFile(file, JSON.stringify(oauth2file), function (err) {
if (err) return console.log(err);
});
});
}
}
Any news on this ? I am trying to authenticate with :
{"web": {
"client_id":"my-client-id",
"project_id":"my-project-id",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"my-client-secret"}
}
But I can't find a way, I still get an error message.
Pull request should fix this: https://github.com/h2non/youtube-video-api/pull/28
Error: Cannot retrieve the token. Timeout exceeded at Timeout._onTimeout (/home/lladmin/ytnode/node_modules/nightmare-google-oauth2/index.js:179:18)
i also getting this error ..what should i do ???
It's broken again as it seems… :(
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.
Do you have an example of such API Driven OAuth2 token retrieval?
What I did for now is create the token once manually and then renew it all the time with a cron job so that I don't have to do it ever again. Ideally, even the first manual step would be unnecessary.
If you stopped supporting that "auto-login" functionality how about removing it from the library to avoid confusion since the remaining parts (once you have a token to use) are great :)
I have no time to work on that, but you can easily bypass the built-in authentication mechanism by overwriting this property with an already authorized OAuth2 instance: https://github.com/h2non/youtube-video-api/blob/master/index.js#L105
When using the feature where it will get a new token each time do I get the following error:
My oauth config is a s follows: (fetch from client_secret.json)
My code: