Youtube Data API - 如何避免 Google OAuth 重定向 URL 授权 [英] Youtube Data API - How to avoid Google OAuth redirect URL authorization

查看:27
本文介绍了Youtube Data API - 如何避免 Google OAuth 重定向 URL 授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求:我正在尝试通过 Java 版 Youtube Data API 将视频上传到我的 Youtube 频道.该请求是从托管在 tomcat 容器上的 war 文件发送的.我的应用程序不适用于外部用户,我只用它来上传我自己生成的视频.在 api 文档和示例 youtube 代码片段的帮助下,我成功地在 youtube 上发布了视频.

Requirement: I am trying to upload videos to my Youtube channel through Youtube Data API for Java. The request is sent from a war file hosted on tomcat container.My application is not for external users and I only use it to upload my own generated videos. With the help of the api documentation and sample youtube code snippets, I have successfully managed to post video on youtube.

问题:问题是每当我尝试运行代码时,都会提示我

Problem: The issue is that whenever I try to run the code, I get prompted for

请在浏览器中打开以下地址:https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload

Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload

由于我在远程服务器上运行此代码,因此我不可能始终在浏览器上打开此 URL.由于我已经在 Google Console 中注册了我的网络应用程序,并获得了一对 Client ID 和 Secret 以及一个 JSON 文件,所以 Youtube 必须允许我默认发布视频,至少是我的频道,不是吗?

Since I run this code on a remote server, it is not possible for me to always open this URL on the browser. Since I have registered my web app in Google Console, and got a pair of Client ID and Secret and a JSON file, so Youtube must allow me to publish videos by default to atleast my channel, isin't it?

我使用了 Auth.java 文件(在 youtube java 代码示例中提供),下面的代码就是发生这种情况的地方.

I have used the Auth.java file(provided in youtube java code samples) and the following code is where this thing happens.

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user@.com");

LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

请在这里提供帮助,因为这真的占用了我很多的开发时间.

Please help here as this is really eating up a lot of my development time.

推荐答案

您应该只需要验证您的代码一次.当您的代码通过身份验证时,您将获得一个刷新令牌.刷新令牌将允许您在下次运行代码时获得新的访问令牌.

You should only need to authenticate your code once. When your code is authenticated you get a refresh token back. the refresh token will then allow you to get a new access token the next time your code runs.

YouTube api 没有服务帐户身份验证.您的代码必须在第一次通过身份验证才能获得刷新令牌.

There is no service account authentication for the YouTube api. Your code has to be authenticated by you the first time in order to get that refresh token.

我不是 Java 程序员,但从快速检查文档来看,它看起来与我在 .net 中所做的非常相似.您需要创建一个数据存储区 存储第一个 refreshh 令牌,然后您应该能够在将来运行您的代码而无需再次对其进行身份验证.

I am not a java programmer but from a quick check of the documentation it looks quite similar to what I do in.net. You need to create a datastore to to store the first refreshh token then you should be able to run your code in the future with out needing to authenticate it again.

这篇关于Youtube Data API - 如何避免 Google OAuth 重定向 URL 授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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