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未经授权
请有人告诉我如何通过成功验证......
答案 0 :(得分: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"
然后使用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\"]},....