Get user email using Youtube API

2019-03-03 05:22发布

问题:

How can I get authenticated user email using Youtube API?

I tried using channels.list:

GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&mine=true&key={YOUR_API_KEY}

It doesn't return the email...

I communicate with Youtube API using this NodeJS module:

var Youtube = require("youtube-api");

Youtube.authenticate({
    type: "oauth",
    token: ACCESS_TOKEN
});

Youtube.channels.list({
    "part": "brandingSettings",
    "mine": true
}, function (err, data) {
    console.log(err, data);
});

回答1:

To get a user's email address, you'll need to get their permission first during OAuth. Google's OAuth has a scope specifically for this. I'm not familiar with the Node.js youtube-api module, but you'll have to get it to include an additional OAuth scope: https://www.googleapis.com/auth/userinfo.email. Then the email address will be available in the response from a request to http://googleapis.com/oauth2/v1/userinfo.

This post may be helpful: http://javascriptplayground.com/blog/2013/06/node-and-google-oauth/