Search code examples
ruby-on-railsvimeovimeo-api

Cannot set redirect_url for upload through API


I am uploading videos to my Vimeo account using the API and the intridea/oauth2 in a Rails application.

This is how I retrieve my upload ticket:

require 'oauth2'
require 'json'
client = OAuth2::Client.new CLIENT_ID, SECRET, site: 'https://api.vimeo.com'
token = OAuth2::AccessToken.new client, TOKEN
response = token.post '/me/videos?redirect_url=https://foobar.com'

body = JSON.parse response.body
puts body['upload_link_secure']

The API endpoint I use is documented here. The provided link in the response looks something like this:

https://1511635511.cloud.vimeo.com/upload?ticket_id=...&redirect_url=https%3A%2F%2Fvimeo.com%2Fupload%2Fapi%3F...

The whole process works fine, the video is uploaded, but as you can see the redirect URL was not replaced with https://foobar.com. This means I won't get the video_id back to my app automatically.

Do you guys see what I am doing wrong?

Cheers

SOLUTION

As explained by Austio parameters for POST are send in the body, not in the url. Also the Vimeo API requires a type to be set to POST. The follogwing snippets works now:

response = token.post '/me/videos', body: { type: 'POST', redirect_url: 'https://foobar.com' }

Or:

response = token.post '/me/videos' do |request|
  request.body = { type: 'POST', redirect_url: 'https://foobar.com' }
end

Solution

  • So problem then is that you are not doing a proper post format. For posts, you will normally put the parameters in the request not in the url. Try something like this.

    token.post('/me/videos') do |request|
      request.params['request_url'] = "https://foobar.com"
    end
    

    Side note, if i am ever having trouble with an API i pull out something like postman (chrome extension) to test that the api is working as expected before troubleshooting the ruby/rails side. You end up starting at too high of an abstraction unless you deeply understand the client you are using to post.