【问题标题】:How do i pull youtube video and descriptiron in Java Script?我如何在 Javascript 中提取 youtube 视频和描述?
【发布时间】:2023-02-21 01:04:52
【问题描述】:

我想为网站构建网页。但我不知道如何在没有任何后端项目的情况下尝试提取这些数据。所以我的问题是如何使用这些组件构建网页?

我为视频编写这段代码

import React from "react";
import PropTypes from "prop-types";

const YoutubeEmbed = ({ Id }) => (
    <div className="video-responsive">
        <iframe
            width="400"
            height="224"
            src={`https://www.youtube.com/embed/${Id}`}
            frameBorder="0"
            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
            allowFullScreen
            title="Embedded youtube"
        />
    </div>
);

YoutubeEmbed.propTypes = {
    embedId: PropTypes.string.isRequired
};

export default YoutubeEmbed;

【问题讨论】:

    标签: javascript web


    【解决方案1】:

    要使用 JavaScript 从 YouTube 提取视频标题和说明,您需要使用 YouTube API。该 API 允许您检索有关 YouTube 视频、频道和播放列表的信息。

    const videoId = 'YOUR_VIDEO_ID';
    const apiKey = 'YOUR_API_KEY';
    
    const url = `https://www.googleapis.com/youtube/v3/videos?id=${videoId}&key=${apiKey}&part=snippet`;
    
    fetch(url)
      .then(response => response.json())
      .then(data => {
        const video = data.items[0];
        const title = video.snippet.title;
        const description = video.snippet.description;
        // Use title and description as needed
      });
    

    【讨论】:

      猜你喜欢
      • 2012-02-08
      • 2019-01-06
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      相关资源
      最近更新 更多