YouTube APIs - Access mutiple youtube channels (Brand Accounts) using Google Admin account

后端 未结 3 847
时光取名叫无心
时光取名叫无心 2020-11-30 06:04

I need to extract information from videos using YouTube Analytics and Reporting Api.

I have access to multiple YouTube Brand Accounts, when I log into YouTube with

相关标签:
3条回答
  • 2020-11-30 06:55

    I fought with this just two days ago. Turns out it IS possible, it's just undocumented and works a bit differently than you'd expect:

    Once I create the credentials in developers console, they will be associated to the Google Account and not to the Brand Accounts.

    I had the same exact misconception when I first tried (even went so far as to find out the brand account's client_id). Turns out you don't want to use the brand's oauth info -- you want to use your own client_id/client_secret to create a refresh token on behalf of the brand account then use that to create auth tokens.

    Steps:

    1. Using your main account create an oauth client_id and client_secret via https://console.developers.google.com/apis/credentials
    2. Edit the client_id/client_secret entry you just added and add "https://developers.google.com/oauthplayground" to the "Authorized redirect URIs" at the bottom of the page.
    3. We're going to create a refresh token the lazy way. Go to https://developers.google.com/oauthplayground/
    4. Click the gears on the top right corner and set access type to "offline", then click "Use your own OAuth credentials" and enter the client_id and client_secret you created in step 1.
    5. Select the scopes you want to give it access to. Click authorize APIs.
    6. Here's the magic bit: You'll now be asked to "Choose an account". Choose the brand account you want to access here, NOT your main account. Since you have permission to access it this'll work fine even though you're using your own client_id and client_secret
    7. Allow the permission access when it prompts you, then you'll be brought back to the oauth playground.
    8. Click "Exchange authorization code for tokens"
    9. Grab the refresh token and use it like normal to generate auth tokens as needed.

    Congratulations, you now have api access to the brand account!

    Hope that helps.

    0 讨论(0)
  • 2020-11-30 07:00

    The YouTube API is different then other google APIs. With other APIs you authenticate access to the full account. However with the YouTube API its channel based. You are going to need to authenticate your application once for each channel.

    onBehalfOfContentOwner

    This parameter is intended for YouTube content partners that own and manage many different YouTube channels. It allows content owners to authenticate once and get access to all their video and channel data, without having to provide authentication credentials for each individual channel. The actual CMS account that the user authenticates with needs to be linked to the specified YouTube content owner.

    You need to be a YouTube partner then you can contact your account manager and get a CMS id. I have yet to figure out what magic one must archive to become a YouTube partner.

    0 讨论(0)
  • 2020-11-30 07:02

    If you follow the solution for getting a permanent refresh token and use Java, this works for me

    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                        .setJsonFactory(JSON_FACTORY)
                        .setClientSecrets(oauth2ClientId, oauth2ClientSecret)
                        .build()
                        .setRefreshToken(oauth2RefreshToken);
    
    
     this.youTubeClient = new YouTube.Builder(httpTransport, JSON_FACTORY, credential)
                        .setApplicationName(APPLICATION_NAME)
                        .build();
    

    Required dependencies

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-youtube</artifactId>
        <version>v3-rev212-1.25.0</version>
        </dependency>
    <dependency>
        <groupId>com.google.auth</groupId>
        <artifactId>google-auth-library-oauth2-http</artifactId>
        <version>0.18.0</version>
    </dependency>
    

    These resources might also help once you have the refresh token:

    • Authenticate programmatically to Google with OAuth2
    • https://blog.timekit.io/google-oauth-invalid-grant-nightmare-and-how-to-fix-it-9f4efaf1da35
    0 讨论(0)
提交回复
热议问题