What scopes do I need to add in OAuth to search YouTube content by geo location?

Viewed 305

I just want to do a simple search of YouTube video content for a keyword by city. I'm currently creating my credentials in the Google Console, but none of the scopes seem the right fit.

I'm assuming I need OAuth, or am I missing a trick with a simplified R script?

Update:

So, following advice, I'm forgetting oAuth. my code is below, but it doesn't work and I'm getting a strange error, "Error: $ operator is invalid for atomic vectors"

enter image description here

1 Answers

According to the official specification of the Search.list API endpoint, you're not required to provide any authorization credentials (as those obtained upon running to successful completion an OAuth 2.0 authentication/authorization flow) for invoking this endpoint as you say you want to.

An Google API developer key suffices -- that's to be provided upon request from Google's Developers Console.

That API key is the to be passed on to Search.list as the key request parameter.

If you still want to use OAuth credentials, then you may choose from the list of YouTube Data API scopes the most restrained one: https://www.googleapis.com/auth/youtube.readonly.

Addendum

So you're using the tuber package.

I looked into its source code and learned that (see the function tuber_GET that is called by yt_search) that this library does not allow one to access the API through an API key. (That because tuber_GET calls yt_check_token; this latter function generates an error when the Google token is missing.)

As a result of these facts, you are forced to follow the OAuth 2 authentication/authorization flow, upon you've configured your Google project (within the Developers Console) to have the scope I mentioned above.

Addendum #2

I would recommend you to file a feature request to the maintainer of tuber, through this package's issue tracker site. (I deem the API key use-case to be of good use to a wider user-base of tuber.)

If you would like to use something else that'll allow you to employ API keys (thus alleviating OAuth 2 flows), then you could use the lower level package httr (which, by the way, tuber is using too).

See Getting started with httr. You may find this tutorial quite valuable: How to Extract Data from YouTube using R and the YouTube API.

Compose an URL with which to invoke Search.list through httrs GET function:

https://www.googleapis.com/youtube/v3/search?key=YOUR_API_KEY&q=dishwasher&type=video&location=-33.8688,151.2093&maxResults=50.

Then, upon calling Search.list, proceed processing the JSON response received.

Related