According to Google documentation, any Google account holder is also a Youtube account holder, but he may not be "linked", i.e. have a Youtube channel. An app can upload video only to a linked account.
If you use AccountManager to get a list of Google account holders, at that point, you can't tell whether any one of them is linked or not. I need a way to find out if it's linked.
There does not seem to be a direct purpose-built call to the Youtube api to see if an account has a channel (is linked).
Maybe the following snippet of the code could be re-purposed to do it:
List<String> scopes = new ArrayList<>();
scopes.add( SendToGoogleUtils."https://www.googleapis.com/auth/youtube.upload" );
if( ( googleAccountCredential = SendToGoogleUtils.getGoogleAccountCredential(
mContext, accountYoutube.name, scopes ) ) == null) return;
String gAToken = googleAccountCredential.getToken();
youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
.setApplicationName(getString(R.string.tourmaker_app_name))
.build();
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setMine(true);
channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
ChannelListResponse channelResult = channelRequest.execute();
If accountYoutube (see code line 4) is linked, this code runs ok, and proceeds to later code that uploads.
If accountYoutube is not linked, the execute statement throws the GoogleJsonResponseException:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden { "code" : 403, "errors" : [ { "domain" : "global", "message" : "Insufficient Permission", "reason" : "insufficientPermissions" } ], "message" : "Insufficient Permission" }
So, this code kind of tells you if the accountYoutube is linked. Would this sort of code be a reasonable way to determine if accountYoutube has a channel (is linked)?
I'm suspicious, because this exception seems a side-effect I may not be able to rely on.
I'm looking for a best-practices way to determine if accounYoutube is linked. I would use the code at an appropriate time to present to User only linked accounts.
Does anyone know a reliable way to do it?