带 OAuth 的 Youtube API 单用户场景(上传视频) [英] Youtube API single-user scenario with OAuth (uploading videos)

查看:34
本文介绍了带 OAuth 的 Youtube API 单用户场景(上传视频)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经有人问过了,但一直没有回答.

This question has been already asked, but never answered.

我想编写一些将视频上传到我自己的 YouTube 帐户的 php 脚本.我已经注册了应用程序并拥有开发者密钥、客户密钥和客户机密.

I want to write some php scripts that would upload video to my own YouTube account. I have already registered the application and have the developer key, the customer key and the customer secret.

我不需要允许任何用户将视频上传到他们自己的帐户,因此我不需要完成完整的 OAuth 流程;特别是我不需要在任何地方重定向任何人:我只需要我的脚本代表我(而不是代表其他任何人)进行身份验证.

I don't need to allow any user to upload video to their own accounts, so I don't need to go through the full OAuth process; especially I don't need to redirect anybody anywhere: I only need my scripts to authenticate on MY behalf (not on anybody else's behalf).

我知道我可以使用 ClientLogin 身份验证,但我在 YouTube API 文档站点上读到不推荐用于新开发",恐怕这意味着对它的支持将在不久的将来停止.所以我更喜欢使用 OAuth.

I know I can use ClientLogin authentication, but I've read on the YouTube API documentation site that it is "not recommended for new development" and I'm afraid this means that support for it will be discontinued in a near future. So I'd prefer to use OAuth.

Twitter API 也使用 OAuth,提供了一种简单的方法来通过应用程序所有者自己的帐户进行身份验证,只需一个步骤,使用您可以在应用程序管理页面上找到的访问令牌.如何为我的 Youtube 应用程序获取类似的令牌?

The Twitter API, which also uses OAuth, provides a simple way to authenticate with the application's owner's own account, in a single step, using an access token that you can find on your application's administration page. How can I obtain a similar token for my Youtube application?

谢谢米.

推荐答案

为已安装的应用程序尝试 OAuth 2.0:http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#OAuth2_Installed_Applications_Flow

Try OAuth 2.0 for installed application: http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#OAuth2_Installed_Applications_Flow

首先注册API,获取client_id.

First, register the API to get a client_id.

然后,登录您的 google 帐户,输入以下 URL,将 client_id 更改为您的.redirect_uri 应设置为urn:ietf:wg:oauth:2.0:oob".

Then, log into your google account, type the following URL, change the client_id with yours. redirect_uri should be set to "urn:ietf:wg:oauth:2.0:oob".

https://accounts.google.com/o/oauth2/auth?client_id=1084945748469-eg34imk572gdhu83gj5p0an5.apps6urgoogleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://gdata.youtube.com&response_type=code&access_type=offline

然后您授权自己的应用程序并获得授权码.

Then you authorize your own application and get an authorization code.

然后打开终端并输入(更改您的代码、client_id 和 client_secret):

Then open a terminal and type (change your code, client_id, and client_secret):

curl https://accounts.google.com/o/oauth2/token -d "code=4/ux5gNj-_mIu4DOD_gNZdjX9EtOFf&client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&client_secret=hDBmMRhz7eJRsM9Z2q1oFBSe&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code"

你会得到如下回复:

<代码>{"access_token": "ya29.AHES6ZTtm7SuokeEB-RGtbBty9IIlNiP9-eNMMQKtXdMP3sfjL1Fc","token_type" : "承载",expires_in":3600,refresh_token":1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74"}

记住refresh_token,每次运行应用程序时,都需要通过refresh_token获取一个新的access_token.

Remember the refresh_token, and every time you run your application, you need to get a new access_token with the refresh_token.

这篇关于带 OAuth 的 Youtube API 单用户场景(上传视频)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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