博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vimeo
阅读量:6690 次
发布时间:2019-06-25

本文共 3321 字,大约阅读时间需要 11 分钟。

  hot3.png

用 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_tokensession[: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.tokenuser.secret = access_token.secretuser.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

你可能感兴趣的文章
SSM前言——相关设计模式
查看>>
小清丽微距花卉拍摄示范
查看>>
GetSysColor()函数可以得到系统的颜色
查看>>
项目积累demo-01
查看>>
JAVA面向对象编程深入理解图
查看>>
jsp与jsp之间传参数如何获取
查看>>
如何做好一名售前工程师 [理论]
查看>>
什么是语法糖?
查看>>
rabbitMQ的安装和创建用户
查看>>
Struts2笔记——第一个实例HelloWorld
查看>>
Maven安装
查看>>
2.1列表相关知识点
查看>>
OpenStack images
查看>>
xsigo systems
查看>>
ofbiz ins
查看>>
iOS动画实现改变frme和contenOffset
查看>>
DroidPilot使用第一步 - 安装
查看>>
vue-cli —— 项目打包及一些注意事项
查看>>
1.1 变量
查看>>
mfc 链接时错误 文件函数重复定义
查看>>