【问题标题】:How can I connect to vimeo by using my website with PHP, Javascript or an API?如何通过 PHP、Javascript 或 API 使用我的网站连接到 vimeo?
【发布时间】:2023-04-10 01:34:01
【问题描述】:

我目前正在开发一个网站,我想自动添加上传到我的 vimeo 帐户的最新视频。我发现我必须首先使用 API,但我不知道有任何 API 可以做到这一点。所以我想出了这个主意:

1 - 首先,使用 php 或 javascript 等从我的网站连接到我的 vimeo 帐户,以最终到达管理页面。

2 - 使用 DOM 获取 HTML,我在视频的 url 中找到了视频的 ID。

3 - 创建一个函数,自动替换 vimeo 在我的网站上为您提供的视频中的 URL 的 ID。

vimeo 给你的代码:

<iframe src="https://player.vimeo.com/video/563338183?badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen style="position:absolute;top:0;left:0;width:40%;height:40%;" title="HIEBEL_GRAND VITRAIL_0621_57400"></iframe><script src="https://player.vimeo.com/api/player.js"></script>

来自 vimeo 的视频的 URL:

https://vimeo.com/manage/videos/123456789/1234a56789

要到达那里,我必须连接。

连接弹窗:

我在网上找到了一些 Jquery 功能,但我认为它不是我要找的:

jQuery(function($){
    $('#result').load('https://vimeo.com/fr/');
});

如果你们有解决办法,我将不胜感激

【问题讨论】:

  • 你当然可以sort the data returned asc/desc 并选择最后一项??
  • 哦,好吧,我不知道。谢谢,这将有很大帮助!
  • TBH 我从未使用过 Vimeo API,但这正是我在查看他们的文档时看到的。
  • 我找到了这篇文章stackoverflow.com/questions/46582015/…,但它似乎真的很复杂。我不明白他们为什么不考虑这么简单的事情......
  • 唉,我无法运行任何测试脚本,因为我还没有将任何视频上传到 Vimeo。我确实运行了我提到的几个参数集的查询,响应表明感兴趣的数据将在 json.data 数组中。您链接到的问题提出了关于隐藏您的 authorisation accesstoken 的问题 - 尽管对您而言这可能不适用,因为您运行查询所需的只是您在 url 中的 userId 号码。

标签: javascript php connection embed vimeo


【解决方案1】:

好的,各位,在尝试了很多之后,我终于找到了一个有效的代码!

这是关键:

import React from "react";
import ReactDOM from "react-dom";
import axios from "axios";

const CLIENT_IDENTIFIER = "***INSERT CLIENT ID***";
const CLIENT_SECRET =
  "***INSERT TOKEN***";

class App extends React.Component {
  state = {
    vimeo: []
  };

  async getVideosForChannel(access_token) {
    const { data } = await axios.get(
      "https://api.vimeo.com/channels/***CHANNEL NAME***/videos?sort=date&direction=desc",
      {
        headers: {
          Authorization: `Bearer ${access_token}`
        }
      }
    );

    this.setState({ vimeo: data.data });
  }

  async componentDidMount() {
    if (!CLIENT_IDENTIFIER || !CLIENT_SECRET) {
      return alert("Please provide a CLIENT_IDENTIFIER and CLIENT_SECRET");
    }

    try {
      const { data } = await axios.post(
        "https://api.vimeo.com/oauth/authorize/client",
        { grant_type: "client_credentials" },
        {
          auth: {
            username: CLIENT_IDENTIFIER,
            password: CLIENT_SECRET
          }
        }
      );

      this.getVideosForChannel(data.access_token);
    } catch (error) {
      if (error.response.status === 429) {
        alert(
          "The Vimeo api has received too many requests, please try again in an hour or so"
        );
      }
    }
  }

  render() {
    return (
      <div className="App">
        <ul>
          {this.state.vimeo.map(({ resource_key, link, name }) => (
            <li key={resource_key}>
              <a id="lien" href={link}>
                {name}
              </a>
              <p>{link}</p>
            </li>
          ))}
        </ul>
      </div>
    );
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

您必须确保已安装 react 以使其正常工作。

(感谢这个家伙https://codesandbox.io/s/pwro9p7w8j?file=/src/index.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 2011-05-31
    • 2017-09-22
    • 2015-05-10
    相关资源
    最近更新 更多