youtube-api, v3, geolocation information - geolocation

Although the youtube-api, v3, allows you to make a request for videos that come from a particular area (for example, by specifying the location and the radius), it appears that the resulting information about the videos does not contain location information. That is, you can't get the reported lat/long of the video itself.
A query for a specific location would look like this:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&key=[key]&location=37,5%2C-120.5&locationRadius=2km&maxResults=5
Here's the description of the information returned.
https://developers.google.com/youtube/v3/docs/search#top_of_page
So, is that correct? Is there no longer any way to find out the lat/long information of a video that is returned in a query?

OK, I figured this out. The location query will only return the various snippets of information about the videos, that is true. However, you can then look at individual videos in more depth to find their locations. For example:
https://www.googleapis.com/youtube/v3/videos?part=recordingDetails&key=[key]&id=HiFnDoUiaqg
will return recording information including:
"recordingDetails": {
"location": {
"latitude": 37.50973,
"longitude": -120.49805,
"altitude": 0.0
},
So it's a 2-step process. You find the list of videos returned by the location query, and then you look at the detailed information for those videos.

Related

Gathering Youtube Top Comments Using YouTube API V3

I'm trying to work with YouTube API V3 to extract the top 10 comments from a specific video. I'm currently using the below line to access the comments for a video. I have successfully grabbed comments from the video in question, but I have been unable to extract the TOP comments like the ones shown under the video on youtube.
https://www.googleapis.com/youtube/v3/commentThreads?key=**YOUTUBEAPIKEY**&textFormat=plainText&part=snippet&videoId=**YOUTUBEVIDEOID**&maxResults=50
I've looked through the documentation at:
https://developers.google.com/youtube/v3/docs/commentThreads/list
But I haven't been able find anything that mentions this. Does anyone know how I could go about doing this?
I think you can do that by using the snippet.viewerRating, if you base the rank of the comment per number of likes as discussed in this SO post. Then you can filter from the most number of like to the least. Placing the top comments at the top.
The rating the viewer has given to this comment. Note that this
property does not currently identify dislike ratings, though
this behavior is subject to change. In the meantime, the property
value is like if the viewer has rated the comment positively.
The value is none in all other cases, including the user having
given the comment a negative rating or not having rated the comment.
Valid values for this property are:
like
none
Here is the sample JSON structure for the comments resource format.
{
"kind": "youtube#comment",
"etag": etag,
"id": string,
"snippet": {
......
"authorChannelId": {
"value": string
},
......
"viewerRating": string,
"likeCount": unsigned integer,
......
}
}

How to find videos using the YouTube API based on a channel ID

So I am playing around with the YouTube API v3 for a web app I am building. I've got the basics down, but I am searching through documentation trying to find a way to filter a returned video list based on a channelID. However this doesn't seem to be possible. Is there way to write a request similar to this pseudocode below:
https://www.googleapis.com/youtube/v3/videos?part=snippet&
// and a second value that would imply with channelID=UCn8zNIfYAQNdrFRrr8oibKw
This seems like a logical function to have in the API. However, I can't seem to find any name/value pair in the documentation to support this theory.
The closest I can seem to find is the onBehalfOfContentOwner name/value pair for the video.list request (but it requires me to be the uploader of the video?) as outlined here
Anyways if someone can answer definitively if this is possible (if yes a link to docs or example I can use) as I've poured over docs looking for this functionality with no luck.
Any help would be much appreciated!
Your link refers to a video search.
1) First, you need to retrieve the channel info for the channelID (e.g. UCn8zNIfYAQNdrFRrr8oibKw).
See: https://developers.google.com/youtube/v3/docs/channels
Get the part:
"contentDetails": {
"relatedPlaylists": {
"likes": string,
"favorites": string,
"uploads": string,
"watchHistory": string,
"watchLater": string
}
2) Then use the "uploads": string, to retrieve the videos, being the user uploaded videos, which is a playlist.
For retrieving playlists see: https://developers.google.com/youtube/v3/docs/playlists .
Use the api call search.list, for example:
GET https://www.googleapis.com/youtube/v3/search?channelId=ASADKAHWSDA&type=video&key={YOUR_API_KEY}
in the query parameters specified the resource type = video because you want the videos of this channel. As cited here https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list
The type parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. (string)
The resource can be anything a video, playlist, subscriber, etc. Hope this help.

twitter search api no place returned

I am having a bit of trouble sifting through the twitter API. I am trying to search for tweets near a certain location and then see their exact (or approximate) geo coordinates. I understand the geo field is deprecated and now we are supposed to use the "place" field. Unfortunately when I use the following url: http://search.twitter.com/search.json?q=&geocode=30.1829,-97.832,10mi I get a bunch of responses with a location that matches the city of the geo coordinates, but geo: is null and there is no place field. Am I stuck with only having an accuracy up to city coordinates, or am I using the wrong search call?
Thanks in advance!
Remember, tweeting with a geo location is an opt-in process. Twitter will supply a feed from the area for all tweeters in that area, but only those who have opted to tweet their coordinates will show up with "geo" info.
Using q=here with your url it did return 1 tweet for me with "geo" info in this form (though likely it will have moved on down the timeline by the time you try...):
"geo":{"coordinates":[-33.9769,18.5080],"type":"Point"}
Every user has a user defined location set in their profile settings. Use this when users don't use geo-encoding.
You can obtain a list of all countries / states by country and do a simple clean-up operation on the dataset.
This gave me what I needed for location data and greatly enriched my output.

Google Map API only returns one result?

I am using the google maps api to develop an iOS app. I need to find the nearest gas station on the map. When I call an http request: http://maps.googleapis.com/maps/api/geocode/json?address=%gas%20station&sensor=true, it returns one result. But it is the only one. There should be many results. No matter what keywords I submit, it only returns one result. Does anyone know how to deal with this?
I opened the URL in a browser and got this response :
{
"results" : [],
"status" : "ZERO_RESULTS"
}
According to Google Maps documentation here
"ZERO_RESULTS" indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
Gas station is a vague address. Try entering a valid address with a name of the area or city or the street. And you will get results. e.g. http://maps.googleapis.com/maps/api/geocode/json?address=250%20King%20St%20SF&sensor=true
You need to use the Places API to search for places like establishments(restaurants, gas stations,etc)
I don't know why, but when I printed the result to the console, it always was showing only one result. But in a debug mode with a breakpoint there were 5 results.
Please check it out using a debug mode.

Get the music genres in YouTube

When we view the YouTube page, and click Music, we are able to see them on different genre's like "Rap", "Rock", "Country", etc.
How can I retrieve this data (the genre-wise listing of videos) using the YouTube Apis.?
One way to do this is using the Topics API integration with V3 of the API. Take a look at the videos.list() API call. Plug in these values:
part: topicDetails
id: fWNaR-rxAic
fields: items/topicDetails/topicIds
The ID of that video corresponds to Carly Rae Jepsen's "Call Me Maybe". When you look at the JSON response, you'll see a list of topic IDs:
[ "/m/015f7",
"/m/0h55y27",
"/m/0gkxzs6",
"/m/064t9" ]
These are Freebase machine IDs. You would then make a Freebase API call to retrieve information about that particular topic. For instance, /m/064t9 corresponds to "Pop Music".
Thise method won't work for 100% of videos on YouTube; Metallica's "Whiskey in a Jar" only returns topics for the song and the band, however, Britney Spear's "I Want to Go" correctly returns a machine ID for "Pop Music".
The reason for this is that the Topic is often machine generated, not human curated (though we do quality checks). We did a Google I/O talk about how this works. The good news is that once you DO have a machine ID, it's very easy to find other videos by topic ID. Our samples demonstrate how to do this.
In freebase you can ask for music genre mids. For example in: http://www.freebase.com/search?query=rock you get that /m/06by7 = rock. With this id you do a query on youtube and get videos regarding this genre;
Try it https://developers.google.com/youtube/v3/docs/search/list#try-it with this conditions:
part: snippet
topicId: /m/06by7
For anyone wondering about this now (2017) freebase is deprecated and so instead you should use the list currently provided here: https://gist.github.com/stpe/2951130dfc8f1d0d1a2ad736bef3b703
Ikai Lan is still correct that the part is topicDetails to get this information from the API.

Resources