[英]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.