如何在 Nodejs 中使用 Vimeo oEmbed API?

发布于 2025-01-20 18:57:56 字数 1831 浏览 3 评论 0原文

我正在开发一个 React Web 应用程序,它可以将视频上传到 Vimeo 并在需要时检索它们。我能够成功私下上传视频。我正在使用隐藏 Vimeo 隐私设置并嵌入特定域选项。上传视频时,我想从后端服务器接收一个可嵌入的 iframe 字符串,以便我可以在我的 React 应用程序中显示视频。
Vimeo API 参考页面上提供的 oEmbed API 在 postman 中运行。但是当我尝试通过 nodejs 字符串获取它时,出现以下错误:

错误:{“错误”:“找不到请求的页面。”} 在传入消息。 (C:\Users\prith\node_modules\vimeo\lib\vimeo.js:164:19) 在 IncomingMessage.emit (节点:事件:402:35) 在 endReadableNT(节点:内部/流/可读:1343:12) 在 processTicksAndRejections (node:internal/process/task_queues:83:21) 状态代码 404 标头 {
连接:'关闭','内容长度':'49',服务器:'nginx',
'content-type':'application/vnd.vimeo.error+json',过期:'Sun, 2022 年 4 月 10 日 20:00:04 GMT', 'cache-control': '私有,无存储, 无缓存', '严格传输安全': 'max-age=31536000; 包括子域;预加载', '请求哈希': '8fa895fc',
'x-bapp-server': 'api-v22576-6dhrr', 'x-vimeo-dc': 'ge',
'accept-ranges': '字节', via: '1.1 varnish, 1.1 varnish',
'fastly-original-body-size':'0',日期:'2022 年 4 月 11 日星期一 08:00:04 GMT', 'x-served-by': 'cache-iad-kiad7000087-IAD, 缓存-maa10229-MAA','x-缓存':'未命中,未命中','x-缓存命中':'0, 0','x-timer':'S1649664004.146166,VS0,VE292',变化: '接受,Vimeo-Client-Id' }

这是我的代码:

vimeo_embed.js

let Vimeo = require('vimeo').Vimeo;

const USER_ID = "USER_ID"
const USER_SECRET = "USER_SECRET"
const USER_TOKEN = "USER_TOKEN"

let client = new Vimeo(USER_ID, USER_SECRET, USER_TOKEN);

client.request({
    method: 'GET',
    path: '/app/oembed.json/',
    query: {url: 'https%3A//vimeo.com/xxxxxxxx'}
},function (error, body, status_code, headers) {
    if (error) {
      console.log('error');
      console.log(error);
    } else {
      console.log('body');
      console.log(body);
    }
   
    console.log('status code');
    console.log(status_code);
    console.log('headers');
    console.log(headers);
  });

我不清楚为什么会引发此错误。我已经验证身份验证有效。 请帮我。

I am working on a react web application that can upload videos to Vimeo and retrieve them when required. I am able to successfully upload the video privately. I am using the hide from Vimeo privacy setting and embed on specific domains option. On uploading the video I want to receive an embeddable iframe string from the backend server so that I can display the video in my react app.
The oEmbed API provided on Vimeo API reference page is working in postman. But when I try to get it through nodejs string I get the following error:

Error: {"error":"The requested page couldn't be found."}
at IncomingMessage. (C:\Users\prith\node_modules\vimeo\lib\vimeo.js:164:19)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) status code 404 headers {
connection: 'close', 'content-length': '49', server: 'nginx',
'content-type': 'application/vnd.vimeo.error+json', expires: 'Sun,
10 Apr 2022 20:00:04 GMT', 'cache-control': 'private, no-store,
no-cache', 'strict-transport-security': 'max-age=31536000;
includeSubDomains; preload', 'request-hash': '8fa895fc',
'x-bapp-server': 'api-v22576-6dhrr', 'x-vimeo-dc': 'ge',
'accept-ranges': 'bytes', via: '1.1 varnish, 1.1 varnish',
'fastly-original-body-size': '0', date: 'Mon, 11 Apr 2022 08:00:04
GMT', 'x-served-by': 'cache-iad-kiad7000087-IAD,
cache-maa10229-MAA', 'x-cache': 'MISS, MISS', 'x-cache-hits': '0,
0', 'x-timer': 'S1649664004.146166,VS0,VE292', vary:
'Accept,Vimeo-Client-Id' }

This is my code:

vimeo_embed.js

let Vimeo = require('vimeo').Vimeo;

const USER_ID = "USER_ID"
const USER_SECRET = "USER_SECRET"
const USER_TOKEN = "USER_TOKEN"

let client = new Vimeo(USER_ID, USER_SECRET, USER_TOKEN);

client.request({
    method: 'GET',
    path: '/app/oembed.json/',
    query: {url: 'https%3A//vimeo.com/xxxxxxxx'}
},function (error, body, status_code, headers) {
    if (error) {
      console.log('error');
      console.log(error);
    } else {
      console.log('body');
      console.log(body);
    }
   
    console.log('status code');
    console.log(status_code);
    console.log('headers');
    console.log(headers);
  });

I am not clear about why this error is thrown. I have verified that the authentiction is working.
Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2025-01-27 18:57:56

我猜Nodejs lib尚未启用端点,正如您在这里看到的: https: //developer.vimeo.com/api/reference#table-1

因此,您需要使用旧方法获取此数据。

I guess the NodeJS lib does not have oembed endpoint yet, as you can see here: https://developer.vimeo.com/api/reference#table-1

So you need to use old way to fetch this data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文