vimeo_me2 icon indicating copy to clipboard operation
vimeo_me2 copied to clipboard

Apply an embed preset to a video?

Open mattgilbertnet opened this issue 4 years ago • 6 comments

Is there a way to apply an embed preset to a video using this gem, either on upload or afterwards given the vimeo ID? The API has support for this: https://developer.vimeo.com/api/reference/embed-presets?version=#add_video_embed_preset

mattgilbertnet avatar Feb 10 '21 14:02 mattgilbertnet

For a little more context, I've tried: $vimeo.put("/videos/#{vimeo_id}/presets/#{preset_id}", code:204)

and got:

Traceback (most recent call last):
        2: from (irb):3
        1: from (irb):4:in `rescue in irb_binding'
VimeoMe2::RequestFailed (VimeoMe2::RequestFailed)

mattgilbertnet avatar Feb 10 '21 15:02 mattgilbertnet

You can get more information about the request by inpsecting the raw HTTParty reponse $vimeo.client.last_request after a failed call. You should get more info on why the request failed. Could you check? Basically when using put you're no longer leveraging the gem itself, but merely the shorthand to make calls directly via HTTParty.

I quickly created a convenience method for this call and updated the gem. So you can do this more easily:

  1. Get your video: vimeo_video = VimeoMe2::Video.new('API_KEY','VIIDEO_ID')
  2. Add a preset to it: vimeo_video.add_preset('1234')

bo-oz avatar Feb 10 '21 17:02 bo-oz

Here's the result of $vimeo.client.last_request (Obfuscated some stuff that idk might be sensitive.):

#<HTTParty::Response:0x230f0 parsed_response="{"error":"The requested page couldn't be found."}", @response=#<Net::HTTPNotFound 404 Not Found readbody=true>, @headers={"connection"=>["close"], "content-length"=>["49"], "server"=>["nginx"], "content-type"=>["application/vnd.vimeo.error+json"], "expires"=>["Wed, 10 Feb 2021 10:16:46 GMT"], "cache-control"=>["private, no-store, no-cache"], "strict-transport-security"=>["max-age=31536000; includeSubDomains; preload"], "request-hash"=>[...], "x-bapp-server"=>[...], "x-vimeo-dc"=>["ge"], "accept-ranges"=>["bytes"], "via"=>["1.1 varnish, 1.1 varnish"], "date"=>["Wed, 10 Feb 2021 22:16:46 GMT"], "x-served-by"=>..., "x-cache"=>["MISS, MISS"], "x-cache-hits"=>["0, 0"], "x-timer"=>[...], "vary"=>["Accept,Vimeo-Client-Id"]}>

mattgilbertnet avatar Feb 10 '21 22:02 mattgilbertnet

Same response from vimeo_video.client.last_request using your convenience method.

mattgilbertnet avatar Feb 10 '21 22:02 mattgilbertnet

This might be helpful: I was able to set the preset using RestClient with:

RestClient.put(
  "https://api.vimeo.com/videos/#{vimeo_id}/presets/#{preset_id}",
  {},
  {
    "authorization": "Bearer #{VIMEO_API_KEY}"
  }
)

The {}, might be a clue.

mattgilbertnet avatar Feb 10 '21 22:02 mattgilbertnet

You can get more information about the request by inpsecting the raw HTTParty reponse $vimeo.client.last_request after a failed call. You should get more info on why the request failed. Could you check? Basically when using put you're no longer leveraging the gem itself, but merely the shorthand to make calls directly via HTTParty.

I quickly created a convenience method for this call and updated the gem. So you can do this more easily:

  1. Get your video: vimeo_video = VimeoMe2::Video.new('API_KEY','VIIDEO_ID')
  2. Add a preset to it: vimeo_video.add_preset('1234')

The URI Path for this is missing a '/' between the base_uri and the preset portion of the path, example I get using this is

/videos/1234preset/1234

Cluster444 avatar Mar 17 '21 13:03 Cluster444