Google Youtube API Search doesn't retrieve all videos in the channel - youtube-api

I have to retrieve all video of my channel with Youtube API.
All videos are published on Youtube and I can see them correctly.
I tried to make the request directly from this page:
https://developers.google.com/youtube/v3/docs/search/list
and this is the example request:
GET http s://www.googleapis.com/youtube/v3/search?part=snippet&channelId=myChannelID&maxResults=50&key={YOUR_API_KEY}
Request doesn't retrieve all videos, it returns only 7 on the total of 9.
All videos have the same configuration. Missing videos are always the same.
If I use the video API passing the ID of one of those videos excluded from the search response, it returns a correct response and it belong correctly to my channel:
https://developers.google.com/youtube/v3/docs/videos/list#try-it
Someone can help me?
thank you in advance
Francesco

The answer to "How do I obtain a list of all videos in a channel using the YouTube Data API v3?" here may be what you need. Look especially at the video linked to in the answer.
To summarize, to get all the uploads from a channel, you need to get the items from the uploads playlist for the channel using playlistItems.list on that playlist's ID rather than calling search.list on the channel ID.
Try this two-step approach:
Get the ID of your channel's uploads playlist using the channels.list API call: GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}
Get the videos from the uploads playlist using the playlistItems.list call: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}

try this
async static Task<IEnumerable<YouTubeVideo>> GetVideosList(Configurations configurations, string searchText = "", int maxResult = 20)
{
List<YouTubeVideo> videos = new List<YouTubeVideo>();
using (var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = configurations.ApiKey
}))
{
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = searchText;
searchListRequest.MaxResults = maxResult;
searchListRequest.ChannelId = configurations.ChannelId;
searchListRequest.Type = "video";
searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;// Relevance;
var searchListResponse = await searchListRequest.ExecuteAsync();
foreach (var responseVideo in searchListResponse.Items)
{
videos.Add(new YouTubeVideo()
{
Id = responseVideo.Id.VideoId,
Description = responseVideo.Snippet.Description,
Title = responseVideo.Snippet.Title,
Picture = GetMainImg(responseVideo.Snippet.Thumbnails),
Thumbnail = GetThumbnailImg(responseVideo.Snippet.Thumbnails)
});
}
return videos;
}
}

Related

MusicKit API - Playlist Update, Delete, Song Remove

I've been looking at the MusicKit functionality for playlists:
https://developer.apple.com/documentation/applemusicapi/create_a_new_library_playlist
I'm wondering, can anyone confirm if they have been able to:
remove songs from an existing playlist
delete a playlist
update the title of a playlist
For example, I have tried updating the title of a playlist in c# using the following but the endpoint does exist/accept this. Note the appended playlist ID to the POST URL p.ABC123
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + [MYDEVTOKEN]);
client.DefaultRequestHeaders.Add("Music-User-Token", [MYMUSICUSERTOKEN]);
string _postUri = "https://api.music.apple.com/v1/me/library/playlists/p.ABC123";
var jsonObject = JObject.FromObject(new
{
attributes = new
{
name = "Playlist - Edited Title",
description = "This is a playlist edit"
}
});
var _content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
var response = await client.PostAsync(_postUri, content: _content);
string outputContent = await response.Content.ReadAsStringAsync();
}
It seems as though Apple isn't allowing this functionality.
https://forums.developer.apple.com/thread/107807
They could be doing this as a security precaution. However, Apple doesn't have a great relationship with the developer community, and is most likely doing it to limit people from building applications on top of theirs. (even though they are an extremely expensive API to work with off the bat...)
I wouldn't anticipate getting this functionality any time soon :(

Youtube API v3 - Get "Live Now" rtmp and streamkey

Youtube now has a Live Streaming section that allows users to broadcast their own live stream sessions. In this "Live Streaming" section, there are 2 options: "Live Now [Beta]" and "Events".
Live Now is a fast and easy way to start a streaming session automatically just by pointing your video encoder to te specified RTMP Url and Stream Key. It will automatically detect incomming media and start broadcasting publicly.
Events is pretty much the same thing, but with advance settings, although it will not start automatically to broadcast, and you need to set everything pretty much manually.
I know Youtube API allows you to retrieve Event's ingestion url and streamkey, so you can broadcast to that target, but it also requires to manage many other steps manually (like publishing the stream, binding broadcasts with streams, check the status, start, stop, etc..). On the other hand "Live Now" makes everything automatically.
Question: How can I retrieve "Live Now" ingestion info (rtmp url and streamkey) from the Youtube API v3 ?
The default broadcast can be retrieved by livebroadcasts.list with broadcastType set to "persistent".
The default livestream can be retrieved by livestreams.list using boundstreamid.
You cannot retrieve "Live Now" ingestion info because the API does not differentiate between "Live Now" and "Events." Those two options are provided as interfaces on top of the API for an end user, so they don't have to write their own application that interfaces with the API.
You will have to manually set up liveBroadcast and liveStream objects, bind them with liveBroadcasts.bind, test your stream, and transition to live on the liveStream object using status.streamStatus.
To Get “Live Now” rtmp and streamkey
$broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts(
'id,snippet,contentDetails',
array(
'broadcastType' => 'persistent',
'mine' => 'true',
));
$boundStreamId = $broadcastsResponse['items']['0']['contentDetails']['boundStreamId'];
$streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,cdn', array(
// 'mine' => 'true',
'id' => $boundStreamId
));
print_r($streamsResponse);
// Keep client_id,client_secret and redirect_uri the client_secrets.json
UserCredential credential;
string BoundStreamId = string.Empty;
string StreamKey=string.Empty;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeReadonly},
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
if (credential != null)
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp" // your app name
});
LiveBroadcastsResource.ListRequest lbRequest = youtubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
lbRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
lbRequest.MaxResults = 10;
lbRequest.Mine = true;
var bcResponse = await lbRequest.ExecuteAsync();
IEnumerator<LiveBroadcast> iLB = bcResponse.Items.GetEnumerator();
while (iLB.MoveNext() && string.IsNullOrEmpty(liveChatId))
{
BoundStreamId = livebroadcast.ContentDetails.BoundStreamId;
}
LiveStreamsResource.ListRequest lsRequest =
youtubeService.LiveStreams.List("id,snippet,cdn,status");
lsRequest.MaxResults = 50;
lsRequest.Id = BoundStreamId;
var srResponse = await lsRequest.ExecuteAsync();
IEnumerator<LiveStream> iLS = srResponse.Items.GetEnumerator();
if (srResponse != null)
{
foreach(LiveStream lvStream in srResponse.Items)
{
StreamKey= lvStream.Cdn.IngestionInfo.StreamName);
}
}
}

Google Youtube API v3 Playlist title new

I am trying to port a application developed using version 2 API of google youtube to version 3.
How can I get title of a playlist using version 3 API? We could get the title of playlist using version 2. However, title I get when I query playlist's snippet is different from what it is shown on the youtube website.
Is there any difference in Version 3?
I am using .NET API library from Google. if this helps.
Can anyone please help?
I tried using Version 3 API from Google and when I am trying to get playlists using
var channelsListRequest = youtubeService.Channels.List("snippet,contentDetails");
after setting channelsListRequest.ForUserName, i call var channelsListResponse = await channelsListRequest.ExecuteAsync();
From the response, I would then get the playlist list sent using:
foreach (var channel in channelsListResponse.Items)
{
var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
var nextPageToken = "";
while (nextPageToken != null)
{
var playlistRequest = youtubeService.Playlists.List("id,snippet,contentDetails,status,player");
playlistRequest.Id = uploadsListId;
playlistRequest.MaxResults = 50;
playlistRequest.PageToken = nextPageToken;
var playlistListResponse = await playlistRequest.ExecuteAsync();
if (playlistListResponse.Items.Count > 0)
MessageBox.Show(playlistListResponse.Items[0].Snippet.Title);
}
}
The messagebox displays the comment that was added when creating playlist. However, when I view in youtube using a browser, the playlist title is displayed properly.

Youtube Data API v3 - Get video feeds of auto-generated channels

I want to use auto-generated channel Ids as example below...
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UCrfjym-5AEUY2QzXsddRIQA&fields=items(id%2Csnippet)&key={YOUR_API_KEY}
...to access their video contents. But seems I cannot make use of the part: 'snippet,contentDetails', or filter:'uploads' filtering method as I use for getting normal user channel Ids before grabbing their playlistItems. Is there a simple method to display video feed or playlist contents of an auto-generated channel? I use the gapi.client instead of the url. Thx for guidance.
FINAL UPDATE:
Here is my solution for auto-generated Topic-based channel ids, since I'm using
gapi.client, here's what works (relevant code only - URL samples below):
function requestUserUploadsPlaylistId(pageToken) {
var itemId = $("#YOUR-TEXT-INPUT").val(CHANNEL-ID); // Topic-based channel Id
var request = gapi.client.youtube.playlists.list({ // Use playlists.list
channelId: itemId, // Return the specified channel's playlist
part: 'snippet',
filter: 'items(id)' // This gets what you only need, the playlist Id
});
request.execute(function(response) {
playlistId = response.result.items[0].id;
requestVideoPlaylist(playlistId, pageToken); // Now call function to get videos
});
}
function requestVideoPlaylist(playlistId, pageToken) {
var requestOptions = {
playlistId: playlistId,
part: 'id,snippet',
maxResults: 6
};
var request = gapi.client.youtube.playlistItems.list(requestOptions);
request.execute(function(response) { // playlistItems.list is used here
. . .
Here's the URL sample of auto-generated Topic-based Id which grabs its playlist id:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=HC9m3exs6zk1U&fields=items%2Fid&key={YOUR_API_KEY} // Outputs sample playlist Id: LP9m3exs6zk1U
Now here's the URL sample using that playlist Id to get the videos from the auto-generated Topic-based channel Id:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5&playlistId=LP9m3exs6zk1U&key={YOUR_API_KEY} // Outputs video data you want.
Remember, Topic-based channel Ids come in different lengths, the above samples support current available lengths.
Hope This Helps!

Why Youtube trhows a NullPointerException when trying to get the editlink

String atomXml = "<?xml version='1.0'?>" +
"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' gd:fields='yt:accessControl' xmlns:yt='http://gdata.youtube.com/schemas/2007'>" +
"<yt:accessControl action='comment' permission='denied'/>"+
"<yt:accessControl action='rate' permission='denied'/></entry>";
System.out.println("Dsiabling Comments and Rating");
GDataRequest request = service.createPatchRequest(new URL(entry.getEditLink().getHref()));
request.getRequestStream().write(atomXml.getBytes("UTF-8"));
request.execute();
System.out.println("Dsiabling Comments and Rating COMPLETED");
In the above code entry is a VideoEntry which was retuned by uploading a video to YouTube. But when I try the code it throws a null pointer exception. Any fix for this. And If there is any other way of setting the comments and rating disabled its fine as well. I do the following once the Video is published.
String updateUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads/"+videoId;
VideoEntry _entry = service.getEntry(new URL(updateUrl), VideoEntry.class);
VideoEntry vToDel = service.getEntry(new URL(_entry.getEditLink().getHref()), VideoEntry.class);
vToDel.delete();
If you want to delete or update a video you cannot take it directly from edit link of the uploaded VideoEntry. You need to query for a new video entry using the same video id. And use that to update or delete.

Resources