繁体   English   中英

Vimeo API身份验证进入Rails应用

[英]Vimeo api authentication into rails app

Vimeo写作提出要求

在拥有经过身份验证或未经身份验证的访问令牌之后(如前几节所述),请通过授权标头发送访问令牌:

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}

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

请有人告诉我如何才能成功认证...

您提到了不同的要求。 要使用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"

然后获得具有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