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

自作多情 提交于 2019-12-11 18:07:59

问题


I am trying to upload a video to YouTube account on behalf of 'user@gmail.com' 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 'admin@gmail.com' and completed the steps in : www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.

  2. I logged in as 'user@gmail.com' and gave permissions to 'admin@gmail.com' 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("my-service-account@test.com")
                    .setServiceAccountPrivateKeyFromP12File(new File("my-service-account.p12"))
                    .setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
                    .setServiceAccountUser("user@email.com")
                    .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!


回答1:


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



来源:https://stackoverflow.com/questions/35916974/upload-video-to-youtube-with-a-service-account-on-behalf-of-a-user-by-server-sid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!