简体   繁体   English

Vimeo API身份验证进入Rails应用

[英]Vimeo api authentication into rails app

Vimeo writing Making Requests Vimeo写作提出要求

After you have either an authenticated or unauthenticated access token (as explained in the preceding sections), send the access token through the authorization header: 在拥有经过身份验证或未经身份验证的访问令牌之后(如前几节所述),请通过授权标头发送访问令牌:

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

and it's work, but in my application I can't be authorized 确实可以,但是在我的应用程序中我无法获得授权

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}

RestClient::Unauthorized: 401 Unauthorized RestClient ::未经授权:401未经授权

Please somebody tell me how I can do authenticated to success... 请有人告诉我如何才能成功认证...

You mentioned different requests. 您提到了不同的要求。 To get an access toket with RestClient do: 要使用RestClient访问令牌,请执行以下操作:

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"

And then get an API endpoints with Bearer authorization: 然后获得具有Bearer授权的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\"]},....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM