Visits by country Api(V3) Youtube - youtube-api

Is it possible to get the number of visits by country of any video only using the ID of that video?
Here is my url but I can´t get it works.
Url:
https://www.googleapis.com/youtube/v3/videos?regionCode=es&id=Rx9OoLwiAho&key={}&part=snippet,contentDetails,statistics,status

No you can't, it is only for user who upload the video. The part of url in which regionCode is given by you. It is only application if The regionCode parameter instructs the API to select a video chart available in the specified region. This parameter can only be used in conjunction with the chart parameter. The parameter value is an ISO 3166-1 alpha-2 country code.
?regionCode=es
For more information You can use this below link.
https://developers.google.com/youtube/v3/docs/videos/list#chart
Hope it helps you.

Related

Youtube - ListChannels with Username(forUsername) is not working

I'm trying to get channels info with ChannelsList. This endpoint has a parameter the name is: forUsername but it does not work for this page: https://www.youtube.com/c/FolkartTr
This is my query and it returns empty data:
Somehow, I got this channelID in the page source and its: "channelId":"[UCnS--2e1yzQCm5r4ClrMJBg]".
When I try to query with this ID it's okay and returns with correct data.
and this is its payload: http://jsonblob.com/941253671862419456
How will I be able to reach this channel info using a username? I got a few links with usernames and I want to get their info with their username. I don't have any chance to get their channelID's for all.
Thanks for your help.
If I understood correctly, your problem is that you can't do anything from such a username with the Channels: list of the YouTube Data API v3. If you're just looking for the channel id linked to this username then because as YouTube Data API v3 doesn't work for this, I would recommend you to use my open-source YouTube operational API, indeed by requesting https://yt.lemnoslife.com/channels?part=snippet&forUsername=FolkartTr you'll receive a JSON with id equals to the channel id linked to the provided forUsername value.
If you have any question don't hesitate to comment or come to the Discord support.
Notice that the channel title and the channel customUrl might be different.
In your example - http://jsonblob.com/941253671862419456 -, the channel title is Folkart, but its customUrl - which is the value you get when view on YouTube - is: folkarttr.
Note the difference in both case-sensitive and additional letters.
For these reasons, you should not based your channel search by name, but, rather, by its channel_id.
If you really need to search by userName, the answer from Benjamin Loison can solve your requirement.
See if you can find a ticket on Issue Tracker or post your issue there too. Then, you might get some official answer.

Get all videos for a given user

I'm trying to find a way to retrieve all videos posted by a given user (eg: https://www.youtube.com/user/laliga/videos).
All the examples I've found online or the doc (https://developers.google.com/youtube/v3/docs/) seems to require either a playlist ID, channel ID or video ID.
Is there any way I can directly query the author's videos or am I forced to retrieve all playlists and then iterate over?
Thanks
You just need to map the user name to its channelID first via the YouTube API like so:
https://www.googleapis.com/youtube/v3/channels?forUsername=USER_NAME&part=id&key=API_KEY
Full docs: https://developers.google.com/youtube/v3/docs/channels/list
Then you can make a Videos:List call with that channelID to get the videos.
1)take your google key id and channel id and put inside below url
https://www.googleapis.com/youtube/v3/search?key=APIKEY&channelId=CHANNELID&part=snippet,id&order=date&maxResults=20
ex
https://www.googleapis.com/youtube/v3/search?key=adsjsdakhkjshd&channelId=sdahghsadhgj&part=snippet,id&order=date&maxResults=20

How can I search the channel in a specific country using the YouTube API 3.0?

I use the url to search channels in a specific country like this https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=8&order=viewCount&q=news&type=channel&regionCode=US&key=API-Key.
But when i changed the regionCode parameter to IT(italy) or any other one,the search result is always identical.So the search result is not changed with the regionCode.
How can I search the channel by country using the YouTube API 3.0,thanks.
I also try to search channel with the optional parameter regionCode, and it seems that this parameter is not to filter the results base on the country code of a Country. I found in this related SO question that the region parameter only applies to movie charts, and is not something that works as a parameter for general searches.
So the only possible parameter that I think you can use to filter the results of YouTube API in a specific country or place is by using the parameter location.
The location parameter, in conjunction with the locationRadius parameter, defines a circular geographic area and also restricts a search to videos that specify, in their metadata, a geographic location that falls within that area. The parameter value is a string that specifies latitude/longitude coordinates e.g. (37.42307,-122.08427).
Hope it helps you.
There is no way to solve this problem. I tried location with locationRadius, but second parameter is limited to 1000km, so, I cant find all videos from Russian Federation or USA using that option and 1 api request.
Also, that api request performs slow for understandable reason.

How to get all comments on a YouTube video?

Since Google has deprecated the YouTube v2 API, I cannot find a way to get all the comments from a video.
Is it possible to use a single, non-deprecated API (Google+, YT v3) to do that?
I am not concerned about maintaining threading.
Believe me it works
https://www.googleapis.com/youtube/v3/commentThreads?key=******************&textFormat=plainText&part=snippet&videoId=kffacxfA7G4&maxResults=50
Key will be provided by the google developer console and 50 denotes 50 comments in form of a json, video id is the id of the video. For any type of queries comment below.
You can get only 100 at most at a time with the comments API. But you get a nextPageToken from the comment api response. Pass &pageToken={nextPageToken} to next api call, until the nextPageToken is undefined. Then you can get all comments if you like.
https://www.googleapis.com/youtube/v3/commentThreads?key={your_api_key}&textFormat=plainText&part=snippet&videoId={video_id}&maxResults=100&pageToken={nextPageToken}
Apparently it is now possible to fetch comment threads.
(old answer)
Currently that's impossible with a first-party tool.
Source:
While v3 offers the majority of v2 functionality, there are currently
a couple of tasks that can only be done with the older API.
Specifically, applications that manage captions or that work with
video comments still need to use the v2 API until modern equivalents
are available. Our goal is to provide similar functionality well
before the April 2015 shut-off date—please subscribe to this blog, the
YouTube Data API v3 revision history page, or follow +YouTubeDev on
Google+ to keep up-to-date. -
http://apiblog.youtube.com/2014/03/committing-to-youtube-data-api-v3.html
TubeKit (YouTube crawling toolkit) might be of help to some.
You can fetch all the comments using https://www.googleapis.com/youtube/v3/commentThreads
The Youtube API v3.0 allows you the following parameters.
textFormat - This parameter indicates whether the API should return comments formatted as HTML or as plain text. The default value is html.
videoId - The Youtube Video ID you want to fetch comments for ( if you dont know your Youtube Video ID, you can get one from Youtube Video ID Finder )
maxResults - The maxResults parameter specifies the maximum number of items that should be returned in the result set.
pageToken - The pageToken parameter identifies a specific page in the result set that should be returned. In an API response, the nextPageToken property identifies the next page of the result that can be retrieved.
$.ajax({
dataType: "jsonp",
type: 'GET',
url: "https://www.googleapis.com/youtube/v3/commentThreads?key=PUT-YOUR-KEYXXXXXXX&textFormat=plainText&part=snippet&videoId=PUT-YOUR-VIDEO-ID",
success: function(result){
data = result;
$('.data').text(data);
console.log(data);
}});
To find PUT-YOUR-KEY(API key) ---> https://console.developers.google.com/apis/credentials then click on blue color button select API key option you can get

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.

Resources