Learn R Programming

SocialMediaLab (version 0.23.2)

GetYoutubeVideoIDs: Extract/scrape the IDs from a set of YouTube video URLs

Description

This function reads a list of YouTube video URLs from a text file and converts them to a vector object. For example, "https://www.youtube.com/watch?v=73I5dRucCds" has the ID "73I5dRucCds". This function can be used to create an object for the argument videoIDs in the function CollectDataYoutube, that is, by extracting the IDs for a set of YouTube videos and compiling them into a vector, ready for collecting data with CollectDataYoutube.

Usage

GetYoutubeVideoIDs(file)

Arguments

file
The connection to read from. This can be a local file, or a http or ftp connection. It can also be a character string with the file name or URI. The file must be plain text format with the URL of each YouTube video specified on a new line (separated by character return). For example, the first line might contain https://www.youtube.com/watch?v=73I5dRucCds, and the second line might contain https://www.youtube.com/watch?v=6S9r_YbqHy8.

Value

a character vector representing a set of YouTube video IDs, each with number of characters equal to 11 (e.g. "73I5dRucCds").

See Also

Use CollectDataYoutube for collecting YouTube comments data.

Examples

Run this code

## Not run: ------------------------------------
#   ## This example shows how to use `GetYoutubeVideoIDs` to extract video IDs from YouTube
#   ## video URLs, and then collect data using the function `CollectDataYoutube`
# 
#   # Use your own Google Developer API Key here:
#   myApiKey <- "1234567890"
# 
#   # Authenticate with the Google API
#   apiKeyYoutube <- AuthenticateWithYoutubeAPI(apiKeyYoutube=myApiKey)
# 
#   # Use the function `GetYoutubeVideoIDs` to automatically generate vector of IDs from
#   # a plain text file of video URLs
#   videoIDs <- GetYoutubeVideoIDs(file="youtube_to_scrape.txt")
# 
#   # Collect the data using function `CollectDataYoutube`
#   myYoutubeData <- CollectDataYoutube(videoIDs,apiKeyYoutube,writeToFile=FALSE)
## ---------------------------------------------

Run the code above in your browser using DataLab