Best answer

Unable to get the correct "Publish date" from the original YouTube video

  • 10 August 2023
  • 10 replies
  • 201 views

Userlevel 1
Badge

I have a simple zap: whenever I put a youtube video on a given playlist, the zap creates a row in google sheet with info relevant to that video: title, link, date published and chanel name. It turns out that the Publish Date I get is the date I put the video on my playlist and not the date when the creators published their videos. See the screenshot.

How do I get “the right publish date”? I mean the original date of publishing the video?

Thank you!

Wojtek
 

 

icon

Best answer by Wojtek108 20 August 2023, 17:43

View original

10 replies

Userlevel 7
Badge +14

Hi @Wojtek108 

Good question.

You may have to use the YouTube API: https://developers.google.com/youtube/v3/docs/videos/list

Zap action: YouTube - API Request

 

Userlevel 1
Badge

ok Thank you! Let us see if anyone has another suggestion.

Userlevel 7
Badge +14

@Wojtek108 

Can you post screenshots with how your Zap steps are configured to make sure we have full context?

Userlevel 1
Badge

Here you go:

 

thank you!

 

Userlevel 1
Badge

I got around the problem by making a macro in google sheets and running it manually on and off. It gives me what I want but it is a semi-automatic solution.

Userlevel 7
Badge +11

Hi there @Wojtek108! 👋

I did some checking and according to YouTube’s API the Published At value is supposed to be the date the video was added to the playlist, not when the video itself was published: 

4d78063863a68ebe78126f2b4b3372c8.png

Glad you were able to come up with a workaround here. I’m not sure what the macro is doing exactly but the only other workaround I could think of would be to:

  • Set up another Zap that uses a New Video In Channel (YouTube) trigger - which should give the date and time the video was actually published (not when it was added to a specific playlist).
  • In that Zap, you’d record information for the videos in another Google Sheets spreadsheet using a Create Spreadsheet Row (Google Sheets) action.
  • Then in your current Zap, you’d use a Lookup Spreadsheet Row (Google Sheets) action to search for that video to retrieve the desired publish date (from the new spreadsheet) and add that into the spreadsheet to record the correct publish date.  

 
If you decide to give that suggested workaround a try and run into any trouble let us know. Happy to help further! 🙂

Userlevel 1
Badge

Hey @SamB!

Thank you for taking the time and looking into the matter. The thing is that I put on my playlist videos from different channels, so it does not make sens  to set up a zap for every channel I run into and find interesting.

 

Thanks again for going to trouble. I appreciate it!

Userlevel 7
Badge +11

Apologies for missing your reply here previously, @Wojtek108

Ah I see! Sorry to hear the alternative workaround I suggested won’t be suitable for your use case here. Seems like sticking with your current semi-automated workaround may be the best way forward for now.

That said, it may also be worth reaching out to YouTube and the Zapier Support team to request that a feature request be opened to also have the date the video was published not just the date the video was added to the playlist. Although it’s not currently possible with YouTube’s API, at least it would make them aware of the need for this and allow us to track user interest. 🙂

Badge

I got around the problem by making a macro in google sheets and running it manually on and off. It gives me what I want but it is a semi-automatic solution.

can you post the macro?

Userlevel 1
Badge

Here you go. You have to though get the indentation right. As I pasted the script, it all got messed up and aligned to the left. But you get the point. Use chatgpt to help you along.

 

function fetchYouTubeVideoPublishedDate(videoId) {

var apiKey = 'xxxxx'; // Replace with your actual API key

var apiUrl = 'https://www.googleapis.com/youtube/v3/videos?id=' + videoId + '&part=snippet&key=' + apiKey;

 

try {

var response = UrlFetchApp.fetch(apiUrl);

var data = JSON.parse(response.getContentText());

 

if (data.items && data.items.length > 0) {

var publishedDate = data.items[0].snippet.publishedAt;

return publishedDate;

} else {

return 'Video not found';

}

} catch (error) {

return 'Error fetching video data';

}

}


 

function pasteVideoPublishedDateToSheet() {

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

var selectedRow = sheet.getActiveRange().getRow();

 

var videoId = sheet.getRange(selectedRow, 5).getValue();

var publishedDate = fetchYouTubeVideoPublishedDate(videoId);

 

var columnToPaste = 6; // Change this to the desired column index

sheet.getRange(selectedRow, columnToPaste).setValue(publishedDate);

}

function createCustomMenu() {

var ui = SpreadsheetApp.getUi();

ui.createMenu('Custom Menu')

.addItem('Paste Video Published Date', 'pasteVideoPublishedDateToSheet')

.addToUi();

}

Reply