2016-08-24 83 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