Learn how to integrate Bolt.new AI with Vimeo and boost your video workflow. Follow our step-by-step guide, discover best practices, and overcome common pitfalls.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
vimeoClient.ts
). In this file, we’ll write a TypeScript class to interact with Vimeo’s API. Paste the following code into vimeoClient.ts
:
export class VimeoClient {
private accessToken: string;
private baseUrl: string = 'https://api.vimeo.com';
constructor(accessToken: string) {
this.accessToken = accessToken;
}
async getVideoInfo(videoId: string): Promise<any> {
const url = ${this.baseUrl}/videos/${videoId};
const response = await fetch(url, {
headers: {
'Authorization': Bearer ${this.accessToken},
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(Failed to fetch video info: ${response.statusText});
}
return await response.json();
}
}
package.json
file in your project’s root. This file tells the project about required packages. Create or update package.json
with the following content:
{
"dependencies": {
"node-fetch": "^2.6.1"
}
}
Note: In some runtimes, the global fetch API is available. If you encounter issues, the above dependency ensures that fetch
is available. In your vimeoClient.ts
file, add the following import line at the very top if needed:
import fetch from 'node-fetch';
app.ts
or another file where you handle API calls), import and use the VimeoClient. Insert the following code snippet where appropriate:
import { VimeoClient } from './vimeoClient';
// Replace 'YOURVIMEOACCESS_TOKEN' with your actual Vimeo access token.
const accessToken = 'YOURVIMEOACCESS_TOKEN';
const client = new VimeoClient(accessToken);
// Replace 'VIDEO_ID' with the Vimeo video ID you wish to fetch info for.
(async () => {
try {
const videoData = await client.getVideoInfo('VIDEO_ID');
console.log('Video Data:', videoData);
} catch (error) {
console.error('Error fetching video info:', error);
}
})();
VIMEOACCESSTOKEN
with your actual token. Then, update your main application code like this:
import { VimeoClient } from './vimeoClient';
// Access the environment variable for the Vimeo access token.
const accessToken = process.env.VIMEOACCESSTOKEN || 'YOURVIMEOACCESS_TOKEN';
const client = new VimeoClient(accessToken);
(async () => {
try {
const videoData = await client.getVideoInfo('VIDEO_ID');
console.log('Video Data:', videoData);
} catch (error) {
console.error('Error fetching video info:', error);
}
})();
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.