vimeo

本文详细介绍了如何使用Ruby特性实现VimeoAPI,包括模块使用、OAuth认证流程及高级API应用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用 ruby 特性实现的 Vimeo API

两个 modules

  • Vimeo::Simple
  • Vimeo::Advanced

require 'rubygems'
require 'httparty'
require 'digest/md5'

从上面可以看见它使用了 'httparty'

所以我们可以从 ’提供方‘ 提供的数据中选择自己所真正需要的  


user_info = Vimeo::Simple::User.info("matthooks")
# =>
# {
#   "id":"888046",
#   "display_name":"Matt Hooks",
#   "created_on":"2008-10-30 14:17:32",
#   "is_staff":"0",
#   "is_plus":"0",
#   "location":"Chicago, IL",
#   "url":"http:\/\/blackholeinthemidwest.com\/",
#   "bio":"",
#   "profile_url":"http:\/\/vimeo.com\/matthooks",
#   "videos_url":"http:\/\/vimeo.com\/matthooks\/videos",
#   "total_videos_appears_ined":2,
#   "total_videos_appears_in":0,
#   "total_videos_liked":2,
#   "total_contacts":3,
#   "total_albums":0,
#   "total_channels":1,
#   "portrait_small":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_30.jpg",
#   "portrait_medium":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_75.jpg",
#   "portrait_large":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_100.jpg",
#   "portrait_huge":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_300.jpg"
# }

这样使用  
user_info["location"]
# => "Chicago, IL"

从其目录结构就不难看出 * Vimeo::Simple * 包括  

Vimeo::Simple::Activity             Vimeo::Simple::Album                 Vimeo::Simple::Channel             Vimeo::Simple::Group         Vimeo::Simple::User            Vimeo::Simple::Video            

而 * Vimeo::Advanced * 则包括 

Vimeo::Advanced::Album                 Vimeo::Advanced::Base             Vimeo::Advanced::Channel             Vimeo::Advanced::Contact               Vimeo::Advanced::Group           Vimeo::Advanced::GroupEvents           Vimeo::Advanced::GroupForums             Vimeo::Advanced::Person        Vimeo::Advanced::Test            Vimeo::Advanced::Upload         Vimeo::Advanced::Video           Vimeo::Advanced::VideoEmbed            

(共12个)             (使用时需要 OAuth !所以你还需要做一些认准)   具体如下:


** First, instantiate the Base class:

base = Vimeo::Advanced::Base.new("consumer_key", "consumer_secret")
** Get a request token, and save the token secret in the session hash.

request_token = base.get_request_token
session[:oauth_secret] = request_token.secret
** Then, send your user to the authorization URL:

redirect_to base.authorize_url
** Once the user has allowed your application to access their account, they will be redirected to the callback URL you set up for your application. You will be given two parameters oauth_token and oauth_verifier. Re-instantiate your Base class, then get an access token.

base = Vimeo::Advanced::Base.new("consumer_key", "consumer_secret")
access_token = base.get_access_token(params[:oauth_token], session[:oauth_secret], params[:oauth_verifier])
# You'll want to hold on to the user's access token and secret. I'll save it to the database.
user.token = access_token.token
user.secret = access_token.secret
user.save
** Now you've got everything you need to use the Advanced API. Let's get a user's videos:

video = Vimeo::Advanced::Video.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
video.get_videos("matthooks")

# => {"videos"=> { ... }, "stat"=>"ok", "generated_in"=>"0.5753"}
Piece of cake.

** Some methods have optional variables. Pass these as a hash at the end of a call.

video.get_all("matthooks", :page => "2", :per_page => "50")

转载于:https://my.oschina.net/kelby/blog/193069

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值