本文介绍了Python oauth为youtube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网络应用程序中实现YouTube认证用户的视频。使用oauth我想连接到youtube apis。以下是我现在使用的github的代码。



我已经使用该代码实现了 vimeo api 。但我不知道为Youtube api。当我要求 request_token

 时,显示此错误;响应[400]> 
>>> r.text
u'parameter_absent\\\
oauth_parameters_absent:oauth_consumer_key& oauth_signature_method& oauth_signature& oauth_timestamp& oauth_nonce& oauth_timestamp& oauth_nonce& oeuth\\\
n\\\
'

这是来自Youtube参考页的示例请求。

  POST / accounts / OAuthGetRequestToken HTTP / 1.1 
主机:www.google.com
内容类型:应用程序/ x-www-form-urlencoded
授权:OAuth
oauth_consumer_key = example.com,
oauth_signature_method =RSA-SHA1,
oauth_signature =wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D,
oauth_timestamp =137131200,
oauth_nonce =4572616e48616d6d65724c61686176 ,
oauth_version =1.0
oauth_callback =http://www.example.com/showcalendar.html

scope =http://www.google .com / calendar / feeds http://picasaweb.google .com / data

我不知道的是我在gist页面。我有这样的

 >>>标题
{'授权':u'oauth_body_hash = xxxxxxxxxxxxxxxxxxxxxxx,oauth_nonce = 62215234,oauth_timestamp = 1340347725,oauth_consumer_key = xxxxxxxxxxx.apps.googleusercontent.com,oauth_signature_method = HMAC-SHA1,oauth_version = 1.0,oauth_signature = xxxxxxxxxxxxxxxxxxxxxxxx,scope = https://gdata.youtube.com,oauth_callback=http://127.0.0.1:8000 / information / youtube /'}

但是,YouTube参考页面显示我们必须使用授权:OAuth。如何在标题中给出?



谢谢!

解决方案

如果您想要给另一个客户端库(其中包含请求),。我没有YouTube示例,但如果您结帐现有示例在GitHub上,您可以按照他们的格式进行身份验证,并针对YouTube的端点发出请求。



现在我意识到有可能无法使用的各种原因另一个图书馆,所以没有硬的感觉,如果你不能。但是我想提及它作为一个选项。


I'm trying to implement youtube authenticated user's videos in my web application. Using oauth I want to connect to youtube apis. Here is the code I took it from github which I'm using now https://gist.github.com/2970845

I already implemented vimeo api with that code. But I don't know for Youtube api. It is showing this error when I'm requesting the request_token

<Response [400]>    
>>>r.text
u'parameter_absent\noauth_parameters_absent:oauth_consumer_key&oauth_signature_method&oauth_signature&oauth_timestamp&oauth_nonce&scope\n\n'

This is the sample request from Youtube reference page https://developers.google.com/accounts/docs/OAuth_ref.

POST /accounts/OAuthGetRequestToken HTTP/1.1
Host: www.google.com
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth
oauth_consumer_key="example.com",
oauth_signature_method="RSA-SHA1",
oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
oauth_timestamp="137131200",
oauth_nonce="4572616e48616d6d65724c61686176",
oauth_version="1.0"
oauth_callback="http://www.example.com/showcalendar.html"

scope="http://www.google.com/calendar/feeds http://picasaweb.google.com/data"

What I'm not sure about is the headers I've shown in the gist page. I'm having like this

>>> headers
{'Authorization': u'oauth_body_hash=xxxxxxxxxxxxxxxxxxxxxxx,oauth_nonce=62215234,oauth_timestamp=1340347725,oauth_consumer_key=xxxxxxxxxxxx.apps.googleusercontent.com,oauth_signature_method=HMAC-SHA1,oauth_version=1.0,oauth_signature=xxxxxxxxxxxxxxxxxxxxxxxx,scope=https://gdata.youtube.com,oauth_callback=http://127.0.0.1:8000/information/youtube/'}

But the youtube reference page shows that we have to use "Authorization: OAuth". How can I give that in the headers?

Thanks!

解决方案

If you wanted to give another client library a shot (which incidentally wraps Requests), there's rauth. I don't have a YouTube example for you, but if you checkout the existing examples on GitHub you can probably follow their format to get authenticated and make requests against YouTube's endpoints.

Now I realize there's all sorts of reasons why you may not be able to use another library, so no hard feelings if you can't. But I wanted to mention it as an option.

这篇关于Python oauth为youtube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:20