上传youtubevideo服务器端
在我的应用程序中,用户可以将video直接上传到我的YouTube频道以公开。
- 我的应用程序的客户端部分获取video并将其上载到我的服务器。
- 我的服务器然后使用Youtube API将video上传到我的 YouTube频道。
这是我实现它的方式:
-
创建了一个新项目: https : //console.developers.google.com/project
-
启用了
YouTube Data API v3
: -
Key for server applications
创建了一个Key for server applications
: -
这是我的java代码:
YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { } })// .setYouTubeRequestInitializer(new YouTubeRequestInitializer("XXXX"))//same as above .setApplicationName("Some Name")//is it important? .build();
其余的java代码与代码示例相同
但我不能让这个工作,我得到:
GoogleJsonResponseException code: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
知道为什么吗? 我可以检查什么?
这里的API KEY是否足够?
谢谢
您需要一个完整的OAuth,也可以用作已安装的应用程序而非服务器应用程序。 用户必须通过OAuth2。 Data API v3不支持服务帐户。
更多信息: https : //developers.google.com/youtube/v3/guides/authentication
您可以在此处查看Java示例: https : //github.com/youtube/api-samples/tree/master/java