问题
In my web app, I have to ask the users for permission to access their YouTube channels.
The authentication url is something like this:
"https://accounts.google.com/o/oauth2/auth?client_id=myClientId&redirect_uri=http://my.redirect.uri&scope=https://www.googleapis.com/auth/youtube.readonly&response_type=code&access_type=offline&approval_prompt=force"
This URL prompts the user to choose a YouTube channel. But in the channel list, the Google/YouTube account also appears. This account isn't linked with any channels directly.
In my app, the users are supposed to select only a channel. My question is, how can I tell if the user selected a channel and not the Google/YouTube account? Is there some method in the YouTube API that can help me know?
I noticed that if the user has selected a channel and I call the channels/list method then the information it returns is as expected but if I call the same method having selected the Google/YouTube account then the channel title is empty. But I'd like to know if there is some other (nicer and cleaner) way to tell if the user has selected a channel or an account.
Thanks!!
回答1:
The appropriate way of doing this is to make the youtube.channels.list(mine=true, part='snippet')
call that you suggest, and to check to see what comes back.
I'm not aware of any "better" approach.
回答2:
From the response of youtube.channels.list(mine=true, part='snippet, status, contentDetails')
call, you can check status.isLinked and contentDetails.googlePlusUserId to get a hint. If it's not linked, you have a channel, if it's linked, it could be either of them. Then you can follow your title approach etc. There is not a definite filter for this.
If you elaborate on your use case, maybe there is a better solution we can suggest.
来源:https://stackoverflow.com/questions/21408330/how-to-check-if-selected-account-is-youtube-channel