Custom form for uploading a video to Vimeo using their PHP API
I’ve been working on a wordpress project in which I had to use vimeo’s api in order to upload a video from the client’s server to his vimeo’s account. The website is a directory of mental therapists and doesn’t only offer a large database of professionals but also allow any unsubscribed therapist to join the site and have his own personal page listed in my clien’ts database through a form of course, so among all the details that a therapist can add to his profile there was this field named “business video link” which allows the user to place a link to a preventative video of him or his business but my client wanted more than that, he asked for the option to upload and host a video in a video streaming website from his site then to automatically show it within the therapist’s profile once the upload is done.
My client had a preference for Vimeo so I started reading their API documentation before engaging in the project. I must admit that it was documented in a clear and friendly way, at the beginning, I believed I could finish the project in no more than two hours because all I thought I will have to do is to add a simple file input in the front-end and just copy some ready php code from Vimeo’s website and past it in the client’s back-end but it turned out that I was wrong. In fact, I lost 3 days on this project, 90% of the time I was debugging and looking why the code isn’t working as supposed. This tutorial will show you how to create a simple working form that uploads a video to Vimeo using PHP. The initial code is provided by Vimeo itself but if you have to come across the same path as me then this tutorial is just going to save you 3 days of unnecessary struggle by giving you the version of code I have come to at the end.
What you need:
before creating your own form, make sure you have the following:
- An access token provided by Vimeo
- Client id and client secret provided by Vimeo
- Upload permission enabled on your Vimeo’s app page
How to get it
first step is to create your app page on Vimeo, just go to the developer section of their site: https://developer.vimeo.com/ then click on “new app”.
After creating your app, go here https://developer.vimeo.com/apps and chose the app you just created
–make sure you request an upload access, without this the form won’t work as you’re only going to get an error, the request may take time before it gets processed, it took 3 days in my case.
-Generate an access token, chose the same options as the image:
– Now just take the client id, access token and client secret from there
Now just use those information to generate your form
Problems you may encounter:
the code may not work directly from the first shot, if this is the case make sure you do the following:
-try the code on your localhost before you test it on your server
-first try with small size video file (maybe a 1mo video file)
-raise the upload max limit and max execution time on your server/localhost php configuration, you can just add the following code to your .htaccess file:
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300