本文介绍了从服务器上传youtube数据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数据API v3视频,而无需打开浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:44