YouTube Data API v3:无需打开浏览器即可从服务器上传视频 [英] YouTube Data API v3: video upload from server without opening the browser

查看:102
本文介绍了YouTube Data API v3:无需打开浏览器即可从服务器上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天都在尝试将视频从我的服务器上传到我的帐户,但浏览器无法访问.我可以在我的桌面上完成,通过运行下面提到的脚本打开浏览器,请求我的权限并完成上传视频所需的完整授权,然后上传视频.

I am trying to upload videos to my account from my server daily where browser access is not there. I could do it on my desktop, where by running the below mentioned script opened up the browser, asked for my permissions and did the complete authorization needed to upload the video and then it uploaded the video.

python upload_video.py --file clips/concatenated.mp4 --title testing --desc empty_dec

/Users/devansh.dalal/Desktop/hackathon/tiktoki/venv/lib/python3.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access upload_video.py-oauth2.json: No such file or directory
  warnings.warn(_MISSING_FILE_MESSAGE.format(filename))

Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?client_id=73183172161-48495o1tqgjgih3v7j218av2bghdcm30.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.upload&access_type=offline&response_type=code

If your browser is on a different machine then exit and re-run this
application with the command-line parameter

  --noauth_local_webserver

Authentication successful.
Uploading file...

但我想要一个不需要手动授权脚本的解决方案,因为我的服务器是完全安全的.请提出建议?

But I want a solution where I don't need to manually authorize the script as my server is fully secure. suggestions please?

推荐答案

首先要注意,API 上传视频所需的授权与您服务器的安全级别无关.您可以阅读文档 OAuth 2.0 for Mobile &桌面应用,详细了解独立计算机上的授权流程.

First note that the authorization required by the API for uploading a video has nothing to do with the level of security of your server. You may read the doc OAuth 2.0 for Mobile & Desktop Apps for thorough info about the authorization flow on standalone computers.

该文档指定了步骤 4第 5 步.通过初始 OAuth 流程,您将获得两个令牌:一个短期访问令牌和一个按需生成访问令牌的刷新令牌.没有浏览器的身份验证是不可能的,但是一旦有了刷新令牌,就可以通过编程方式将其交易为访问令牌:

The doc specifies steps 4 and step 5. By the initial OAuth flow, you get two tokens: a short-lived access token and a refresh token that produces access tokens on demand. Authentication without browser is not possible, but once having a refresh token, it can be traded programmatically for access tokens:

  1. 初始化:通过浏览器认证获取刷新令牌;

  1. Initialization: obtain via browser authentication a refresh token;

迭代:根据需要多次,查询 API 以获取访问令牌——无需任何浏览器交互!-- 使用 (1) 中的刷新令牌,然后继续调用目标 API 端点(同样,没有任何浏览器交互).

Iterations: as many times as needed, query the API for an access token -- without any browser interaction! -- using the refresh token from (1), then proceed further with the call to the target API endpoint (again, without any browser interaction).

请注意,步骤 (1) 和 (2) 可以很好地分开,以便 (1) 由将刷新令牌存储到文件中的独立(本地)计算机执行;稍后,在另一台远程计算机(例如,未安装浏览器的服务器)上安全传输该文件时,在该远程计算机上执行 (2),根据需要重复执行(请参阅将 OAuth 2.0 用于服务器端独立脚本.)

Note that the steps (1) and (2) may well be separated such that (1) is executed by a standalone (local) computer that stores the refresh token into a file; later, upon a secure transfer of that file on a different remote computer (e.g. a server that does not have a browser installed), execute (2) on that remote computer, repeatedly as needed (see Using OAuth 2.0 for server-side, standalone scripts.)

这篇关于YouTube Data API v3:无需打开浏览器即可从服务器上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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