2011-09-07 20 views
1

我想上傳一張照片,但需要使用flickr進行驗證才能這樣做。我現在用的是flickraw寶石,但不明白下面的說明:如何使用Flickraw來驗證flickr寶石

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 

有人能向我解釋一下這個代碼在做什麼,我應該如何使用它。

回答

1

首先,你應該打開HTTP服務

rails server 

在控制檯,你會看到

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

你必須複製網址並張貼在您的瀏覽器。

登錄後,你會得到一個數字,像

xxx-xxx-xxx 

只是把它複製到你的主機!

0
  1. 創建一個新的Flickr應用程序。從那裏獲取api密鑰和共享密鑰。
  2. 「flickr.get_request_token」從flickr創建一個請求oauth標記。您可能需要將權限設置爲:如果要上載而不是以下內容,請將其寫入:delete
  3. auth_url是您必須重定向到的位置。該網址還包含您剛剛創建的oauth請求令牌。
  4. 一旦您進入auth_url頁面(爲此您必須登錄到您的Yahoo!帳戶),您可以授權您的應用訪問您的flickr帳戶。這提供了一個驗證ID。
  5. 使用該驗證ID你可以得到使用此方法調用flickr.get_access_token「
  6. OAuth訪問令牌一旦你的OAuth訪問令牌,你可以做在Flickr上,你的任何API查詢:燙髮會允許。

整個過程在這裏詳細說明 - http://www.flickr.com/services/api/auth.oauth.html

0

我提交pull請求,但這裏是文檔的更新形式,應該使這一更加清晰

== 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 
    ...