如何使用 Flickraw gem 向 flickr 进行身份验证

发布于 2024-12-03 10:12:19 字数 775 浏览 3 评论 0原文

我想上传照片,但需要通过 flickr 进行身份验证才能上传。我正在使用 flickraw gem,但不明白下面的说明:

require 'flickraw'

FlickRaw.api_key="... Your API key ..."
FlickRaw.shared_secret="... Your shared secret ..."

token = flickr.get_request_token(:perms => 'delete')
auth_url = token['oauth_authorize_url']

puts "Open this url in your process to complete the authication process : #{auth_url}"
puts "Copy here the number given when you complete the process."
verify = gets.strip

begin
  flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
  login = flickr.test.login
  puts "You are now authenticated as #{login.username}"
rescue FlickRaw::FailedResponse => e
  puts "Authentication failed : #{e.msg}"
end

有人可以向我解释一下这段代码在做什么以及我应该如何使用它。

I want to upload a photo but need to authenticate with flickr in order to do so. I am using the flickraw gem but don't understand the instructions below:

require 'flickraw'

FlickRaw.api_key="... Your API key ..."
FlickRaw.shared_secret="... Your shared secret ..."

token = flickr.get_request_token(:perms => 'delete')
auth_url = token['oauth_authorize_url']

puts "Open this url in your process to complete the authication process : #{auth_url}"
puts "Copy here the number given when you complete the process."
verify = gets.strip

begin
  flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
  login = flickr.test.login
  puts "You are now authenticated as #{login.username}"
rescue FlickRaw::FailedResponse => e
  puts "Authentication failed : #{e.msg}"
end

Can someone explain to me what this code is doing and how I should use it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薔薇婲 2024-12-10 10:12:20

我提交了拉取请求,但这里是文档的更新形式,应该使这一点更加清晰

 == Simple

+#Place near the top of your controller i.e. underneath FlickrController < ApplicationController
  require 'flickraw'

+#Create an initializer file i.e. Flickr.rb and place it in config -> initializers folder
  FlickRaw.api_key="... Your API key ..."
  FlickRaw.shared_secret="... Your shared secret ..."

+#Examples of how the methods work
  list   = flickr.photos.getRecent

  id     = list[0].id
  ...

I submitted a pull request but here is an updated form of the documentation that should make this more clear

 == Simple

+#Place near the top of your controller i.e. underneath FlickrController < ApplicationController
  require 'flickraw'

+#Create an initializer file i.e. Flickr.rb and place it in config -> initializers folder
  FlickRaw.api_key="... Your API key ..."
  FlickRaw.shared_secret="... Your shared secret ..."

+#Examples of how the methods work
  list   = flickr.photos.getRecent

  id     = list[0].id
  ...
揽月 2024-12-10 10:12:19

打开 http 服务

 rails server 

首先,您应该在控制台上

Open this url in your process to complete the authication process : http://xxxx.xxxx.xxxx.xxxx........

,您将看到必须复制 url 并将其发布到浏览器上。

登录后,您将获得一个号码,只需

 xxx-xxx-xxx

将其复制到您的控制台即可!

First , you should open http service

 rails server 

On the Console , you will see

Open this url in your process to complete the authication process : http://xxxx.xxxx.xxxx.xxxx........

you have to copy the url and post it on your browser.

After log in , you will get a number , like

 xxx-xxx-xxx

just copy it onto your console!

旧夏天 2024-12-10 10:12:19
  1. 创建一个新的 Flickr 应用程序。从那里获取 api 密钥和共享密钥。
  2. “flickr.get_request_token”从 flickr 创建请求 oauth 令牌。如果您想上传,您可能需要将权限设置为 :write 而不是 :delete
  3. auth_url 是您必须重定向到的位置。该 url 还包含您刚刚创建的 oauth 请求令牌。
  4. 进入 auth_url 页面后(为此,您必须登录您的 Yahoo! 帐户),您可以授权您的应用程序访问您的 flickr 帐户。这给出了一个验证 ID。
  5. 使用该验证 ID,您可以使用此方法调用“flickr.get_access_token”获取 oauth 访问令牌。
  6. 一旦您拥有 Oauth 访问令牌,您就可以在 :perms 允许的 flickr 上执行任何 api 查询。

整个过程在这里详细描述 - http://www.flickr.com/服务/api/auth.oauth.html

  1. Create a new Flickr app. Get the api key and shared secret from there.
  2. "flickr.get_request_token" creates a request oauth token from flickr. You might want to set permissions to :write if you want to upload instead of :delete
  3. auth_url is where you have to redirect to. That url also contains the oauth request tokens that you just created.
  4. Once you are in auth_url page ( for this you have to login to your Yahoo! account), you can authorize your app to access your flickr account. This gives a verification id.
  5. Use that verification id to you can get the oauth access tokens using this method call 'flickr.get_access_token'
  6. Once you have the Oauth access tokens, you could do any api queries on flickr that your :perms would allow.

The entire process is described in detail here - http://www.flickr.com/services/api/auth.oauth.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文