I'm looking to modify YouTube API Apps Script to allow comma separated values in a prompted; or alternative method.
I have been learning how to pull data from the YouTube API through Apps Script using the following example: https://developers.google.com/youtube/v3/quickstart/apps-script
I am able to execute the code but now I'm looking to learn how to be able to add multiple string values to the prompt. In the example, you add a channel name (string) and it will output an ID and view count. I would like to see how you can allow the script to take multiple values.
Add: RedBull, JimmyKimmelLive, ESPN as an example. I believe the call needs to be modified in the below code with the getResponseText. Although, I'm not sure if you would have to call it a different way to allow more than one value.
var ui = SpreadsheetApp.getUi();
var channelName = ui.prompt("Enter the channel name: ").getResponseText();
channelsListByUsername('snippet,contentDetails,statistics',
{'forUsername': channelName});
RedBull, JimmyKimmelLive, ESPN
.RedBull, JimmyKimmelLive, ESPN
, and give them to channelsListByUsername()
.If my understanding is correct, how about this modification? Please think of this as just one of several answers. The flow of this modified script is as follows.
RedBull, JimmyKimmelLive, ESPN
to the prompt.split()
.channelsListByUsername()
.
trim()
for this situation.var ui = SpreadsheetApp.getUi();
var channelName = ui.prompt("Enter the channel name: ").getResponseText();
var values = channelName.split(",");
for (var i = 0; i < values.length; i++) {
channelsListByUsername('snippet,contentDetails,statistics', {'forUsername': values[i].trim()});
}
,
. If you want to other patterns, please tell me.If I misunderstood your question and this was not the result you want, I apologize.