YouTube Data API v3 video upload 403 forbidden: Yo

2019-01-20 17:11发布

I am trying to use the new YouTube Data API v3 to upload video to youtube on Android, but I am getting a 403 forbidden error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
01-22 00:10:41.716: WARN/System.err(5209): {
01-22 00:10:41.716: WARN/System.err(5209): "code" : 403,
01-22 00:10:41.716: WARN/System.err(5209): "errors" : [ {
01-22 00:10:41.716: WARN/System.err(5209): "domain" : "youtube.header",
01-22 00:10:41.716: WARN/System.err(5209): "location" : "Authorization",
01-22 00:10:41.716: WARN/System.err(5209): "locationType" : "header",
01-22 00:10:41.716: WARN/System.err(5209): "message" : "Forbidden",
01-22 00:10:41.716: WARN/System.err(5209): "reason" : "youtubeSignupRequired"
01-22 00:10:41.716: WARN/System.err(5209): } ],
01-22 00:10:41.720: WARN/System.err(5209): "message" : "Forbidden"
01-22 00:10:41.720: WARN/System.err(5209): }

The code is as follow:

I got the OAuth2.0 credential, and I used it to create an instance of youtube:

   YouTube youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                    .setApplicationName("testapp/1.0")
                    .build();

   # ... creating video to save space ...

   youTube.videos().insert("snippet,statistics,status", video, mediaContent).execute();

Any Idea?

Thanks

标签: youtube-api
3条回答
霸刀☆藐视天下
2楼-- · 2019-01-20 17:29

It sounds like you're trying to upload a video into an unlinked Google account. That scenario is covered in this blog post to some extent, though the focus of that post is v2.1 of the API.

When it comes to v3, you still can't upload a video into an unlinked Google account, and there's no API call to allow a user to programmatically link an account. Your best bet would be to take the user to http://m.youtube.com/create_channel and they can take care of the linking there from a browser, at which point they'd have to return to your app and attempt the upload again.

查看更多
Animai°情兽
3楼-- · 2019-01-20 17:35

I solved it and my answer is here: How to insert video youtube api v3 through service account with ruby Enjoy!

The error you are getting is because you didn't add the person tag with the email to upload the movie to. It is all solved and working if you use the code in my answer

查看更多
干净又极端
4楼-- · 2019-01-20 17:55

You can use this mobile workflow in a WebView to have the user create the channel without leaving your app:

https://m.youtube.com/create_channel?chromeless=1&next=/channel_creation_done

To process will take the user to /channel_creation_done once completed, and you can close the WebView then. You can find more information about the workflow here: https://developers.google.com/youtube/create-channel

查看更多
登录 后发表回答