Why Can't I Get a YouTube Video Link from the "New Video in Channel" Trigger and Are There Any Workarounds?

This topic was automatically generated from Slack. You can find the original thread here.

Seems i cannot get youtube video link from trigger “new video in channel”. are there any workaround?

I’m sorry for the inconvenience. To help you better, I’ll need more information about your workflow. Can you please provide more details about the trigger you’re using and what you’re trying to achieve? This will help me understand the issue and provide a suitable workaround.

i want to get the youtube video link whenever a new video is posted in a youtube channel

To get the YouTube video link whenever a new video is posted in a channel, you can use the Pipedream’s YouTube trigger “New Video in Channel”. Here’s how you can set it up: 1. Create a new workflow in Pipedream. 2. Add the “New Video in Channel” trigger from the YouTube app. 3. Configure the trigger by providing the YouTube channel ID. 4. Add a new action or code step to process the new video data. In the code step, you can access the video link using steps.trigger.event.videoUrl. Here’s an example of a code step that logs the video URL: ```
export default defineComponent({ async run({ steps }) { console.log(“New video URL:”, steps.trigger.event.videoUrl); }, });

there is no videoUrl variable

Apologies for the confusion earlier. You’re right, there’s no videoUrl variable in the “New Video in Channel” trigger. Instead, you can construct the video URL using the videoId. Here’s how you can do it in a code step: ```
export default defineComponent({ async run({ steps }) { const videoId = steps.trigger.event.videoId; const videoUrl = https://www.youtube.com/watch?v=${videoId}; console.log(“New video URL:”, videoUrl); }, });

seems the author changed his youtube link, the constructed way wont open his video, any workdaround

I apologize for the confusion earlier. If the video URL constructed using the videoId doesn’t work, it’s possible that the video has been removed or the video URL format has changed. To ensure you’re getting the correct video URL, you can use the YouTube Data API to fetch video details using the videoId. Here’s an example of how to do this in a Pipedream code step: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const videoId = steps.trigger.event.videoId; const apiKey = "YOUR_YOUTUBE_API_KEY"; // Replace with your YouTube API Key try { const response = await axios(this, { method: "GET", url: "https://www.googleapis.com/youtube/v3/videos", params: { id: videoId, key: apiKey, part: "snippet", }, }); if (response.items.length > 0) { const videoUrl = `https://www.youtube.com/watch?v=${videoId}`; console.log("New video URL:", videoUrl); } else { console.log("Video not found"); } } catch (error) { console.error("Error fetching video details:", error); } }, }); Replace YOUR_YOUTUBE_API_KEY with your actual YouTube API Key. This code step will fetch video details using the YouTube Data API and construct the video URL using the videoId. If the video is not found, it will log “Video not found”.

can i use the code you provide to fetch someone else’s video id?

Yes, you can use the provided code to fetch video details for someone else’s video as long as you have the videoId. Just replace the videoId variable in the code with the desired video’s ID, and the code will fetch the video details using the YouTube Data API. Make sure to use a valid YouTube API Key in the apiKey variable.