You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过YouTube API 3.0获取频道总分享数及全部评论

Answers to Your YouTube API & OBS Integration Questions

1. How to Get Your Total Lifetime YouTube Shares via the API

First, a quick heads-up: The YouTube Data API doesn’t provide a direct channel-wide total share count. That 862 number is the sum of shares across all your videos. Here’s how to calculate it:

  • Step 1: Grab your channel’s uploads playlist ID
    Use the channels.list endpoint to fetch your channel’s content details. Replace YOUR_CHANNEL_ID and YOUR_API_KEY with your values:

    GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=YOUR_CHANNEL_ID&key=YOUR_API_KEY
    

    Look for contentDetails.relatedPlaylists.uploads in the response—this is the playlist holding all your uploaded videos.

  • Step 2: Fetch all video IDs from the uploads playlist
    Use playlistItems.list to pull video IDs. Results are paginated (max 50 per call), so use the pageToken from each response to get the next set of videos:

    GET https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=UPLOADS_PLAYLIST_ID&maxResults=50&key=YOUR_API_KEY
    

    Collect all contentDetails.videoId values from every page.

  • Step3: Sum the share counts
    Batch up to 50 video IDs per call to videos.list with the statistics part:

    GET https://www.googleapis.com/youtube/v3/videos?part=statistics&id=VIDEO_ID_1,VIDEO_ID_2,...&key=YOUR_API_KEY
    

    Grab statistics.shareCount for each video (note: some videos might not have this field if no shares exist), then add all these numbers together to get your total lifetime shares.


2. How to Get All Channel-Level Comments

To fetch comments posted directly to your channel (not tied to specific videos), use the commentThreads.list endpoint with the channelId parameter:

  • Example API call:
    GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&channelId=YOUR_CHANNEL_ID&maxResults=100&key=YOUR_API_KEY
    
  • This returns top-level channel comments and their replies. Use the pageToken from each response to paginate through all comments (since results are limited to 100 per call).
  • This data should match the recent comments shown in your YouTube dashboard, as it includes unfiltered comments as requested.

##3. OBS Display with PHP: Local Setup vs. Website
You don’t need a public website—you can run PHP locally for this use case:

  • Set up a local server: Install a stack like XAMPP, WAMP, or MAMP. These include everything you need (Apache web server + PHP) to run scripts on your computer.
  • Create your PHP script: Write a script that fetches the YouTube data (share count + latest comments) and outputs it in a clean, OBS-friendly format (simple HTML with large text, minimal styling).
  • Add auto-refresh: Include a meta tag in your script’s HTML to refresh the page periodically (e.g., every 30 seconds):
    <meta http-equiv="refresh" content="30">
    
  • Connect to OBS: In OBS, add a "Browser" source and point it to http://localhost/your_script.php—this will pull live-updated data from your local PHP script.

##4. Clear Steps to Get a YouTube API Key
Here’s a straightforward walkthrough:

  1. Go to the Google Cloud Console.
  2. Create a new project (or select an existing one).
  3. Search for "YouTube Data API v3" in the API Library, then click "Enable".
  4. Navigate to the "Credentials" section in the left sidebar.
  5. Click "Create Credentials" > "API key".
  6. Copy the generated API key.
  7. Restrict your key (critical!): Under "API restrictions", select "YouTube Data API v3" to prevent unauthorized use. You can also add IP restrictions if you’re only using the key locally.

##5. Low-Coding Direction for Local PHP + OBS Integration
If you want to minimize coding, here’s a path to follow:

  • Start with pre-built snippets: Look for simple PHP scripts that fetch YouTube API data (e.g., channel stats, comments) from trusted sources. Modify these to fit your needs (like summing share counts).
  • Use automation tools for API calls: Tools like Zapier or Make can handle the API fetching and store the data in a local JSON/text file. Then, write a tiny PHP script to read this file and format it for OBS—this avoids writing complex API pagination logic.
  • Prioritize simplicity: First get the share count working in a basic PHP script, then add the latest comments. Keep the output clean (no fancy styling unless you want it) so OBS can display it easily.
  • Test incrementally: Run your script locally first to make sure it’s fetching data correctly, then add it to OBS. Adjust the refresh rate as needed to balance freshness and API usage limits.

内容的提问来源于stack exchange,提问作者GU KingOfHeart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:42:49