Youtube API V3 Java无需调用浏览器即可上传视频 [英] Youtube API V3 Java Any possible without invoking browser to upload video

查看:237
本文介绍了Youtube API V3 Java无需调用浏览器即可上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我希望有人可以帮助我。

Hi I hope someone can help me out here.

我的本​​地计算机上有一个Java应用程序,我正在尝试将视频上传到YouTube。

I have a Java Application on my local machine,I am trying to upload video to YouTube.

将视频上传到经过身份验证的用户的频道。使用OAuth 2.0来授权请求​​。

Upload a video to the authenticated user's channel. Use OAuth 2.0 to authorize the request.

它运行良好。

源自Youtube API V3的源代码。
类名是com.google.api.services.samples.youtube.cmdline.data.UploadVideo

The source code getting from Youtube API V3. The class name is com.google.api.services.samples.youtube.cmdline.data.UploadVideo

我每天都在运行应用程序第一次询问在视频上传到youtube后点击批准后,调用默认浏览器。第二次不调用默认浏览器。它运作良好。

While I run the application everyday asking very first time invoking default browser once i click approve after that video upload to youtube. Second time not invoking default browser. It was working good.

但我想要不调用浏览器,需要将视频上传到youtube。

But I want without invoking browser, Need to upload video to youtube.

任意想法?请与我分享。

Any Idea ? Please share me.

推荐答案

我遇到了和你一样的问题,我想出来了。您可以在 YouTube API v3 Java授权中找到答案

I had the exact same problem as you did, and I figured it out. You can find the answer at YouTube API v3 Java authorization

抱歉,没有意识到不鼓励仅限链接的答案。我很高兴我解决了这个问题。添加以下详细信息:

Sorry, didn't realize link-only answers were discouraged. Just was so pleased that I solved the problem. Adding the details below :

我找到了实现此目的的方法并找到了它。我按照 https://developers.google.com/identity/protocols/OAuth2ServiceAccount

I looked for ways to accomplish this and found it. I followed the instructions at https://developers.google.com/identity/protocols/OAuth2ServiceAccount

您需要一个新的OAuth客户端ID,并将其设置为开发人员控制台中的服务帐户 - API& auth - 凭据,然后下载P12密钥。

You need a new OAuth Client ID and set it up as an "Service account" in the Developers Console - APIs & auth - Credentials, and then download the P12 key.

您还需要从开发人员控制台将服务帐户的权限更改为是所有者。

You also need to change the Permissions of the service account to "Is owner" from the Developers Console.

然后更改代码

Credential credential = Auth.authorize(scopes, "uploadvideo");

GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(emailAddress)
.setServiceAccountPrivateKeyFromP12File(new File("MyProject.p12"))
.setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.setServiceAccountUser("user@example.com")
.build();

,如上面的网址所示。 emailAddress是服务帐户的电子邮件地址,必须更改P12文件名,集合.~~~应更改为范围(原始示例中的预制文件),最后serviceAccountUser应为您的原始Gmail ID。

as specified in the URL above. emailAddress is the email address from the service account, the P12 filename must be changed, Collections.~~~ should be changed to scopes (the premade one in the original example), finally the serviceAccountUser should be your original Gmail ID.

我用上述方法取得了成功,希望有所帮助。

I succeeded with the above method, hope it helps.

这篇关于Youtube API V3 Java无需调用浏览器即可上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆