3
votes

I have read most of the developer console references.

  1. I've created an installed project in the Google Developers Console under the "YouTube Manager Google account" of the YouTube site.
  2. I've enabled YouTube Data API v3 and YouTube Analytics v1.
  3. I've created a credential for an installed project.

The code authenticates with no problem:

UserCredential credential;
            using (var stream = new FileStream(hds_opo_youtube_service.Properties.Settings.Default.clientIDFile, FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    // This OAuth 2.0 access scope allows for read-only access to the authenticated 
                    // user's account, but not other types of account access.
                    new[] { YouTubeService.Scope.YoutubeReadonly,
                            YouTubeAnalyticsService.Scope.YtAnalyticsReadonly},
                    "user",
                    CancellationToken.None,
                    new FileDataStore(this.GetType().ToString())
                );
            }

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = this.GetType().ToString()
            });
I can get the list of videos from one specfic playlist using the youtube data API. Then I create a youtube analytics service and try querying for view data. That is when I get the:

An Error occurred: Google.Apis.Requests.RequestError Forbidden [403] Errors [ Message[Forbidden] Location[ - ] Reason[forbidden] Domain[global] ]

I have tried to resolve the situation using the API Explorer. It has been very helpful. When I try to authenticate using the YouTube Manager Owner profile account. The query fails. But if I use the Google+ page account, which is different, I can get the query to work. The Google+ page account has an email account but all correspondence with the Google+ page account is directed to the manager owner profile account. So I tried to add the Google+ page account to the project permissions, but there is no way of confirming the link. I think my problem is that the YouTube Channel is owned by the Google+ page account. The manager owner assigned has a different account, a profile account, even though it is the manager of the youtube account. I know this sounds really confusing. Does anyone have any ideas on how to solve the problem. Thanks

1

1 Answers

1
votes

Well, I guess I will answer my own question. The YouTube channel is linked to a Google+ business page. This page is not a Google account in the full sense of the word. It has an auto-generated email, but it is not a real email account. The owner manager is a google+ profile account. I didn't understand this distinction before creating my app, so when I initially attempted to authenticate I was given a chose between authenticating the Google+ page or the Google+ profile. I chose the Google+ profile, thinking it was the owner of the youtube channel. Then all the subsequent authentications used the stored refresh token and didn't ask again which of the two google+ accounts to authenticate against. Meanwhile I used the API Explorer and realized I needed to authenticate against the Google+ page. So I deleted the stored refresh token, then ran the code again. It gave me a chose of the two accounts. I chose the Google+ page and the youtube analytics query worked.