I'm trying to implement a search of the most popular videos by tag with Youtube API v3, and encountered a problem when videos sorted by Relevance have more views than those that were sorted by View count.
export const videoList = async (p = null, args: any): Promise<VideoItems | undefined> => {
try {
const {q, maxResults = 5} = args || {};
const youtube = google.youtube({auth: process.env.GOOGLE_CLIENT_API_KEY, version: 'v3'});
const resp: any = await youtube.search.list({
part: 'snippet',
order: 'relevance',
relevanceLanguage: 'en',
regionCode: 'us',
type: 'video',
q: `#${q}`,
maxResults
});
return {
items: resp?.data?.items?.map((item: VideoItem) => (
{id: item?.id?.videoId, title: item?.snippet?.title})
)
};
} catch (err) {
console.log(err);
}
This behavior is reproduced in a native YouTube search:
By relevance: https://www.youtube.com/results?search_query=%23Equality+of+triangles&sp=CAA%253D
By View count: https://www.youtube.com/results?search_query=%23Equality+of+triangles&sp=CAM%253D
- Is there a better way to get the most popular videos by tag with high numbers of views other than
order: 'relevance'? - Why do videos sorted by relevance have more views than those sorted by View count?