Shahar
Shahar

Reputation: 3

Upload video to YouTube with a service account on behalf of a user by server side data API V3

I am trying to upload a video to YouTube account on behalf of '[email protected]' by YouTube data API V3 and I receive 'access_denied' error. According to google documentation:

  1. I opened a service account using a google administrator account '[email protected]' and completed the steps in : www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.

  2. I logged in as '[email protected]' and gave permissions to '[email protected]' service account I created in step 1. (in www.console.developers.google.com/permissions/projectpermissions 'permissions' tab => 'add members') add member

This is my request (JAVA) :

 youtube = new YouTube.Builder(
            GoogleAuthImpl.HTTP_TRANSPORT,
            GoogleAuthImpl.JSON_FACTORY,
            new GoogleCredential.Builder()
                    .setTransport(HTTP_TRANSPORT)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId("[email protected]")
                    .setServiceAccountPrivateKeyFromP12File(new File("my-service-account.p12"))
                    .setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
                    .setServiceAccountUser("[email protected]")
                    .build()
    )
            .setApplicationName("My App")
            .build();

And this is the response: com.google.api.client.auth.oauth2.TokenResponseException: 403 Forbidden { "error" : "access_denied", "error_description" : "Requested client not authorized." } at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)

Is it possible to upload video on behalf of users? Am I doing something wrong?

Also, I found a link to YouTube data API - Oauth 2.0 flows that may indicate that this operation (of exporting to YouTube on behalf of another user via service account) is not supported: www.developers.google.com/youtube/v3/guides/authentication#OAuth2_Flows

Would appreciate a lot your response!

Upvotes: 0

Views: 933

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117271

The YouTube API doesn't support service accounts you need to use Oauth2.

Upvotes: 0

Related Questions