Skip to content Skip to sidebar Skip to footer

Vimeo Api Get Request In Javascript

I'm trying to get information about videos hosted by Vimeo (from my client's channel, so no rights issues). I'm using Javascript, specifically d3.js. The request works fine when us

Solution 1:

Vimeo's API documentation is not the best, so you have to dig a little around to actually get the information you need. In your case, you do not need to go through the whole OAuth2 loop if you are simply requesting data from endpoints that do not require user authentication, such as retrieving metadata of videos, as per your use case.

First, you will need to create a new app, by going to https://developer.vimeo.com/apps:

Create a new Vimeo app

You can simply generate a Personal access token from your Vimeo app page under the section that says Generate an Access Token:

Generating an access token in Vimeo

Remember that this token will only be visible once (so copy it when it is generated): and you have to keep it secure! The access token should be part of the Authorization header's bearer token. If you are using cURL, it will look like this:

curl -H "Authorization: Bearer <YourPersonalAccessToken>" https://api.vimeo.com/videos/123456789

Therefore, while you can do the following on your page to retrieve video metadata on the clientside, note that you are actually exposing your private token to the world:

d3.json("https://api.vimeo.com/videos/123456789/")
  .header("Authorization", "Bearer <YourPersonalAccessToken>")
  .get(function(error, data) {
    console.log(data);
  });

However, I strongly recommend that you proxy this request through your own server, i.e. create a custom endpoint on your server, say /getVimeoVideoMetadata. This API endpoint will receive the video ID, and will add the secretly stored access token you have on your server before making the request. This will mask your access token from your website visitors.

Post a Comment for "Vimeo Api Get Request In Javascript"