2016-08-24 28 views
0

Vimeo的寫入發出請求Vimeo的API認證成軌應用

你要麼經過身份驗證的或未經認證的訪問令牌(如在前面的章節中說明的)後,通過授權標頭中發送的訪問令牌:

curl -H "Authorization: Bearer <OAUTH_TOKEN>" https://api.vimeo.com 

和它的工作,但在我的應用程序不能被授權

RestClient.post 'https://api.vimeo.com/oauth/authorize/client', {grant_type: 'client_credentials', client_id: Rails.application.secrets.vimeo_id, client_secret: Rails.application.secrets.vimeo_secret} 

RestCli耳鼻喉科::未經授權:401未經授權

請有人告訴我我該怎麼辦認證的成功......

回答

0

你提到了不同的要求。 要使用RESTClient實現獲得訪問toket做:

r = RestClient::Request.execute(method: :post, 
          url: "https://api.vimeo.com/oauth/authorize/client", 
          payload: {grant_type: "client_credentials"}, 
          user: VIMEO_CLIENT_ID, 
          password: VIMEO_CLIENT_SECRET) 
=> "{\"access_token\":\"scrt12334\",\"token_type\":\"bearer\",\"scope\":\"public\",\"app\":{\"name\":\"test\",\"uri\":\"/apps/79881\"}}" 

token = JSON.parse(r)['access_token'] 
=> "scrt12334" 

,然後得到與承載授權的API端點:

methods = RestClient::Request.execute(method: :get, url: "https://api.vimeo.com", payload: {}, headers: {"Authorization"=>"Bearer #{token}"}) 

=> "{\"endpoints\":[{\"path\":\"https://api.vimeo.com/\",\"methods\":[\"GET\",\"OPTIONS\"]},.... 
+0

感謝的ü這麼多! – Vitalik

+0

很高興能夠提供幫助。你能否將答案標記爲已接受?謝謝! – retgoat