带有 OAuth 的 Youtube API 单用户场景(上传视频)
这个问题已经被问过,但从未得到回答。
我想编写一些 php 脚本来将视频上传到我自己的 YouTube 帐户。我已经注册了该应用程序并拥有开发人员密钥、客户密钥和客户密钥。
我不需要允许任何用户将视频上传到他们自己的帐户,因此我不需要经历完整的 OAuth 流程;特别是我不需要将任何人重定向到任何地方:我只需要我的脚本代表我(而不是代表其他任何人)进行身份验证。
我知道我可以使用 ClientLogin 身份验证,但我在 YouTube API 文档网站上读到“不建议用于新开发”,恐怕这意味着对它的支持将在不久的将来停止。所以我更喜欢使用 OAuth。
Twitter API 也使用 OAuth,它提供了一种简单的方法,使用您可以在应用程序管理页面上找到的访问令牌,一步一步对应用程序所有者自己的帐户进行身份验证。 如何为我的 Youtube 应用程序获取类似的令牌?
谢谢 米。
This question has been already asked, but never answered.
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.
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).
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.
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?
Thanks
m.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试对已安装的应用程序使用 OAuth 2.0:http://code.google.com/ apis/youtube/2.0/developers_guide_protocol.html#OAuth2_Installed_Applications_Flow
首先,注册 API 以获取client_id。
然后,登录您的 Google 帐户,输入以下 URL,将 client_id 更改为您的。 redirect_uri 应设置为“urn:ietf:wg:oauth:2.0:oob”。
<一href="https://accounts.google.com/o/oauth2/auth?client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.c om&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://gdata.youtube.com&response_type=code&access_type=offline" rel="noreferrer">https://accounts.google.com/o/oauth2/auth?client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleuserconte nt.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://gdata.youtube.com&response_type=code&access_type=offline
然后您授权自己的应用程序并获得授权码。
然后打开终端并输入(更改您的代码、client_id 和 client_secret):
您将得到如下响应:
{
"access_token" : "ya29.AHES6ZTtm7SuokEB-RGtbBty9IlNiP9-eNMMQKtXdMP3sfjL1Fc",
"token_type" : "承载者",
“过期时间”:3600,
“刷新令牌”:“1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74”
}
记住refresh_token,每次运行应用程序时,都需要通过refresh_token获取新的access_token。
Try OAuth 2.0 for installed application: http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#OAuth2_Installed_Applications_Flow
First, register the API to get a client_id.
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-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.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.
Then open a terminal and type (change your code, client_id, and client_secret):
You will get response like:
{
"access_token" : "ya29.AHES6ZTtm7SuokEB-RGtbBty9IIlNiP9-eNMMQKtXdMP3sfjL1Fc",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74"
}
Remember the refresh_token, and every time you run your application, you need to get a new access_token with the refresh_token.