Rails 3 gdata 站点范围的 YouTube 客户端
我想在 Rails 中使用 youtube 的 api。
我需要一个能够在应用程序范围内访问 youtubes api 的客户端。 因此我编写了以下应用程序控制器,
require 'gdata'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :auth
def auth
@client = GData::Client::YouTube.new
@client.clientlogin('usermail', 'password')
@client
end
end
我现在可以在扩展 ApplicationController 的控制器中使用客户端。 工作正常。 但它相当慢。
有没有一种方法可以进行一次身份验证并在应用程序范围内使用它,而不是起诉每次调用方法之前都会调用的 before_filter ?
最好的,
菲利普
i want to uses youtube's api within rails.
I need a client which is able to access youtubes api application wide.
therefore i wrote the following application controller
require 'gdata'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :auth
def auth
@client = GData::Client::YouTube.new
@client.clientlogin('usermail', 'password')
@client
end
end
i am able to use the client now in my controllers which extend ApplicationController.
thats working fine.
but its pretty slow.
is there a way to do the authentication once and using it application wide instead of suing the before_filter which is getting called every single time before i call a method?
best,
philip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个网页。网页是无状态的。因此你无法保留任何状态。因此,您无法在请求之间保留您的登录信息。因此,您必须对每个请求进行身份验证。
另一种方法是仅对某些控制器操作运行 before 过滤器。现在它在每一个动作上运行,但我没有必要这样做。
尝试:
(PS这可能是错误的语法——我很困惑,因为rails变化太大——只要查一下)
This is a web page. Webpages are state-less. Thus you cannot preserve any state. Thus you cannot preserve your login across requests. Thus you have to auth every request.
An alternative would be to only run the before filter on certain controller actions. Right now it runs on every action, which my be not necessary.
Try:
(P.S. That might be the wrong syntax -- I'm confused 'cause rails changes so much -- just look it up)