简体   繁体   English

使用vimeo ruby​​ gem通过访问脚本访问Vimeo API

[英]Accessing Vimeo API via access script using the vimeo ruby gem

I would like to grab the thumbnail urls of a list of restricted videos. 我想获取受限视频列表的缩略图网址。

I created an app with vimeo and got an access token. 我使用vimeo创建了一个应用,并获得了访问令牌。

How do I use this access token to gain access to the method? 如何使用此访问令牌来访问该方法? When I try this: 当我尝试这个:

videos = Vimeo::Advanced::Video.new("client_identifier", "client_secret", 
    :token => "access_token")
videos.get_thumbnail_urls(the_video_id)

I get 我懂了

Vimeo::Advanced::RequestFailed: 401: Permission Denied, explanation: The oauth_token passed was either not valid or has expired.

My users don't have vimeo accounts so I don't see the point (or a way) have them authenticate with vimeo. 我的用户没有vimeo帐户,因此我看不到使用vimeo进行身份验证的要点(或方式)。 I would like to grab the thumbnails of videos uploaded by the same account which created the app. 我想获取由创建该应用程序的同一帐户上传的视频的缩略图。 My understanding is that the access token I generated ought to provide this access. 我的理解是,我生成的访问令牌应该提供此访问权限。

What am I missing? 我想念什么?

Update: Here's what worked for me, based on the accepted answer 更新:这是我接受的答案的依据

require 'httparty'

video_id = "123456789"   # substitute with the desired video ID
api_url = "https://api.vimeo.com/videos/#{video_id}/"  
auth = "Bearer access_token_generated_by_vimeo"    # use your access token
r = HTTParty.get api_url, headers: { "Authorization" => auth, "Accept" => "application/vnd.vimeo.*+json;version=3.2" }  # make sure to use the proper Accept header as recommended in the API docs
v = JSON.parse(r)
v["pictures"]["sizes"][1]["link"]

The Advanced API is Vimeo's old API. Advanced API是Vimeo的旧API。 This has been deprecated, and many of the libraries still only work with this old API. 不推荐使用此方法,并且许多库仍然只能使用此旧API。

Luckily the new API is very easy and you don't really need a library. 幸运的是,新的API非常简单,您实际上不需要库。 Particularly if all you want is thumbnail access. 特别是如果您只需要缩略图访问权限。

Authentication 认证

Take a look at the docs for Single vs. Multi user applications on the dev site . 看一下开发站点上的单用户和多用户应用程序的文档。 Since your users don't have vimeo accounts you should follow the instructions for a single user account (basically hard code a single access token. You can generate this token on your app page under the "Authentication" tab". 由于您的用户没有vimeo帐户,因此您应按照单个用户帐户的说明进行操作(基本上是对单个访问令牌进行硬编码。您可以在“身份验证”标签下的应用页面上生成此令牌)。

API Requests API请求

The new API uses a much cleaner authentication and request structure. 新的API使用更简洁的身份验证和请求结构。 Thumbnails are provided alongside all video responses. 所有视频回复旁边都提供了缩略图。 This includes https://api.vimeo.com/videos/{video_id} , https://api.vimeo.com/me/videos , https://api.vimeo.com/channels/{channel_id}/videos and more. 这包括https://api.vimeo.com/videos/{video_id} , https://api.vimeo.com/me/videoshttps://api.vimeo.com/channels/{channel_id}/videos和更多。

Vimeo recommends you include your access token in a header (Authorization: bearer {token}) but the system does allow you to provide it through the URL (?access_token={token}). Vimeo建议您在标头(授权:bearer {token})中包含访问令牌,但系统确实允许您通过URL(?access_token = {token})提供访问令牌。

A final request could look like 最终请求可能看起来像

GET https://api.vimeo.com/me/videos
Authorization: bearer abcd1234

Ruby 红宝石

Unfortunately I'm not familiar with ruby, so I can't help with translating this to ruby, but there's likely a great HTTP library out there that can help you. 不幸的是,我对ruby并不熟悉,因此我无法将其翻译为ruby,但是那里可能有一个很棒的HTTP库可以为您提供帮助。

This is what worked for me to get a video id from a query string after much experimentation (with thanks to all the above posters). 经过大量的实验(这要归功于上述所有海报),这对我来说是从查询字符串中获取视频ID的工作。

escaped_title = CGI::escape(title)
api_url = "https://api.vimeo.com/videos?query=#{escaped_title}&sort=relevant&access_token=#{@access_token}"
vimeo_response = JSON.parse(HTTParty.get api_url)
vimeo_id = vimeo_response["data"][0]["uri"]

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

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