YouTube API V3 - Get recommended video for new feed - youtube

As YouTube official documentation about implement and immigrate to API V3, they said:
YouTube Data API (v2) functionality: Retrieve video recommendations
The v3 API does not retrieve a list that only contains videos recommended for the current API user. However, you can use the v3 API to find recommended videos by calling the activities.list method and setting the home parameter value to true.
But now the parameter home has been deprecated too.
Currently, when I set the home parameter to true, I only retrieve the recently uploaded video in the channel: Popular video in YouTube. There are no video with snippet.type=recommendation at all.
I need to show recommended videos of authenticated user in new feed, but seem like this feature is completely deprecated by YouTube.
Anyone has solution for that?
Thanks first!

Unfortunately, I can't find any documentation or example about this feature. It seems that this has been deprecated. However, you may check this documentation with sample JSON structure that shows the format of a activities resource such as recommendation:
"recommendation": {
"resourceId": {
"kind": string,
"videoId": string,
"channelId": string,
},
Hope this helps!

I found this youtubes search api. All we need to do is put a video id in the relatedToVideoId and it'll giveout a list of videos related to it.

The docs for the api include a way to test the request. code samples there show how to set 'mine' for an authenticated request.
youtube activities
This is android sample code. it would need to be in some background thread. The setmine = true on the channelList response is like the home (I think). Was not sure if your implementation was for the web or an app.
this is android code:
YouTube youtube = new YouTube.Builder(transport, jsonFactory,
credential).setApplicationName(getString(R.string.app_name))
.build();
YouTube.Activities.List activities;
ActivityListResponse activityListResponse = null;
List<ActivityData> activitiesData = new ArrayList<ActivityData>();
try {
/*
* Now that the user is authenticated, the app makes a
* channels list request to get the authenticated user's
* channel. Returned with that data is the playlist id for
* the uploaded videos.
* https://developers.google.com/youtube
* /v3/docs/channels/list
*/
ChannelListResponse clr = youtube.channels().list("contentDetails")
.setMine(true).execute();
activities = youtube.activities().list("id,snippet,subscriberSnippet");
activities.setChannelId(clr.getItems().get(0).getId());
activities.setMaxResults((long) 50);
activityListResponse = activities.execute();
ArrayList<String> subscriptionListIdentifier = new ArrayList<String>()
,listTitles = new ArrayList<String>()
,listThumbnails = new ArrayList<String>();
List<Activity> results = activityListResponse.getItems();
for (Activity activity : results) {
listTitles.add(activity.getSnippet().getTitle());
listThumbnails.add(activity.getSnippet().getThumbnails().getDefault().getUrl());
subscriptionListIdentifier.add(activity.getId());
//if ("public".equals(playlist.getStatus()
// .getPrivacyStatus())) {
ActivityData data = new ActivityData();
data.setActivity(activity);
activitiesData.add(data);
//}
}
return activitiesData;

You can retrieve them using the following API call:
GET https://www.googleapis.com/youtube/v3/activitiespart=snippet%2CcontentDetails&channelId={channel—_Id}&maxResults=25&regionCode=tw&key={YOUR_API_KEY}

Related

YouTube IFrame Player API getVideoData is removed: how to get title?

On November 13th, I got a call from a customer reporting that the YouTube player didn't work anymore. After a quick look in the dev tool, I found that there was an error:
Uncaught TypeError: a.getVideoData is not a function
Looking into what the player object was containing, I learned that there's no function getVideoData anymore.
The function getVideoData provided a way to get the video title. Now, how can I get the title?
Is there any article from Google about this change?
To get a video's title, you can query the YouTube Data API v3:
GET https://www.googleapis.com/youtube/v3/videos
?part=snippet
&id=VIDEO_ID
&key=YOUR_API_KEY
For that you need to sign up on the Google Cloud Console and create an API key (it's free). You can restrict the API key to only be used from your website, that way you can safely make it public in your JS source code/html code without others being able to make queries on your behalf. Make sure to enable the YouTube Data API v3 in the console as well, otherwise your queries will return errors.
The above query will return a JSON representation of the information on the video that you are interested in (the snippet part). Say you parse the JSON into an object called result. Then you can get the video title via
result.items[0].snippet.title
getVideoData() seems to be back (Dec, 2017). So, try again !
As of today (October 1st, 2020), I am retrieving the title of the video from within YouTube's API object:
// Assigning YouTube's ID to your ID variable
const playerID = "xxxxxxx";
// Creating an object for the video using YouTube's API.
const yPlayer = new YT.Player(playerID, {
events: {
'onReady': onPlayerReady(),
'onStateChange': onPlayerStateChange()
}
});
function onPlayerReady() {
}
function onPlayerStateChange() {
// Title retrieved here
let videoTitle = yPlayer.j.videoData.title;
}
onYouTubeIframeAPIReady();

How to search for multiple twitter ids in one request using twitter4j library

How to search for multiple twitter ids in one request using twitter4j library. Even using in clause in Search parameter would be helpful. Please help!
Please find some sample code below to fetch tweets based on tweet_ids.
Like other twitter API's, this API is also rate limited, in a single call you can fetch status only for 100 ids. Check the documentation for more details.
Also use latest version of twitter4j lib.
ConfigurationBuilder config = new ConfigurationBuilder();
config.setOAuthConsumerKey("consumerKey");
config.setOAuthConsumerSecret("consumerSecret");
config.setOAuthAccessToken("accessToken");
config.setOAuthAccessTokenSecret("accessSecret");
Twitter twitter = new TwitterFactory(config.build()).getInstance();
long ids[] = new long [3];
ids[0] = 568363361278296064l;
ids[1] = 568378166512726017l;
ids[2] = 570544187394772992l;
ResponseList<Status> statuses = twitter.lookup(ids);
for (Status status : statuses) {
System.out.println(status.getText());
}

Google Youtube API v3 Playlist title

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?
EDITED: 20-MAY-2014
Sorry for the delay in response. 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.
Please try the following link, and change the play
https://www.googleapis.com/youtube/v3/playlists?part=snippet%2Clocalizations&id=" + playlistId + "&fields=items(localizations%2Csnippet%2Flocalized%2Ftitle)&key=" + KEY;
Implementation and Migration Guide: https://developers.google.com/youtube/v3/guides/implementation
I am new to the YouTube API implementation, so please use the Implementation and Migration Guide above for more information, but from what I have discovered myself using the API Explorer: https://developers.google.com/apis-explorer/#p/youtube/v3/. Is that you need to use youtube.playlists.list(snippet,[id]). Replace [id] with the ID of your playlist.

YouTube v3 API (.NET) - Get URI of newly posted video resource?

After scouring the v3 API documentation (and using the API explorer), I am not able to determine how to obtain the URI of a newly uploaded video resource (or any video resource).
I am aware that the video's ID is readily available and it is trivial to construct a URI from the ID. For example, I have this extension method:
public static Uri GetUri(this Video video)
{
var uriBuilder = new UriBuilder
{
Scheme = Uri.UriSchemeHttp,
Host = "youtu.be",
Path = video.Id,
};
return uriBuilder.Uri;
}
However, it seems strange that the video resource would not include a few different URLs (regular, shortened and embed-able come to mind).
I also recognize I am probably over thinking this because the only volatile part of the URL is the video ID. I guess I could always put the host name in a config file :)
Thoughts and comments are appreciated.
Regards,
You can get the video ID from the upload response once your request is executed.
YouTube API samples have a great upload example for this.
Once you have the video id, you can construct the full URL as
youtube.com/watch?v={video_id}
youtu.be/{video_id}

Get a playlist entry by ID with YouTube API (PHP)?

I'm currently in the middle of a project that involves YouTube API. I'm using the Zend Gdata, and everything has gone nicely until this.
I need to get a Zend_Gdata_YouTube_PlaylistListEntry based on the ID of the playlist. I have managed to retrieve the videos with some fiddling:
$feed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/api/playlists/'.$id.'?v=2');
$playlist = new Zend_Gdata_YouTube_PlaylistListEntry($feed->getDOM());
However, I need to use the method $playlist->getPlaylistVideoFeedUrl(), and it returns NULL in this case.
Any help regarding this is appreciated =)
Got it:
$url = 'http://gdata.youtube.com/feeds/api/playlists/'.$input['id'].'?v=2';
$feed = $yt->getPlaylistVideoFeed($url);

Resources