Getting YouTube user profile fails with 401 Unauth

2019-08-30 00:22发布

问题:

I was able to replicate this problem in the OAuth 2.0 Playground by authenticating with an account that doesn't have a YouTube channel/username, and calling the Get User method (https://gdata.youtube.com/feeds/api/users/default).

回答1:

It is possible to have a YouTube account without having a YouTube channel (i.e. having a YouTube username). Google calls this an unlinked account.

Some methods defined in version 2.0 of the YouTube API will throw 401 Unauthorized errors if you call them on an unlinked account. It turns out that there is a relatively undocumented version of the YouTube API (version 2.1) that enables functionality for unlinked accounts.

More info: http://apiblog.youtube.com/2011/10/introducing-google-account-support-and.html

I was able to fix the error in the OAuth 2.0 Playground by simply changing the version header from GData-Version: 2.0 to GData-Version: 2.1.



标签: youtube-api