Using the youtube analytics api or youtube data api, is there a way to get the video from a channel with the most comments? - youtube-api

I've been trying for some days now by reading the docs to figure out how to use any of the two APIs mentioned in the title to retrieve a channel's most commented video.
This query doesn't work:
curl --location --request GET 'https://youtubeanalytics.googleapis.com/v2/reports?ids=channel==MINE&dimensions=video&metrics=comments&maxResults=1&sort=-comments&startDate=2022-07-12&endDate=2022-09-12'
But querying for the same dimension but for the views metric instead works:
curl --location --request GET 'https://youtubeanalytics.googleapis.com/v2/reports?ids=channel==MINE&dimensions=video&metrics=views&maxResults=1&sort=-views&startDate=2022-07-12&endDate=2022-09-12'
One weird thing is that even though the documentation specifies that ascending order sorting is working by default (Docs: A comma-separated list of dimensions or metrics that determine the sort order for YouTube Analytics data. By default the sort order is ascending. The - prefix causes descending sort order. ) you can't run some requests without specifically using descending order. For example the views request above.
But changing the sort parameter to sort=view (Ascending) results in the following response:
{
"error": {
"code": 400,
"message": "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.",
"errors": [
{
"message": "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.",
"domain": "global",
"reason": "badRequest"
}
]
}
}
And removing the sort parameter has the same result.
Anyone knows how to solve this mystery with the youtube analytics api?

By using YouTube Data API v3 endpoints you can get the most commented video on a given channel.
Indeed by:
fetching all video ids from the channel by using PlaylistItems: list with part=snippet and playlistId=UPLOADS_PLAYLIST_ID where UPLOADS_PLAYLIST_ID is the channel id with its second character (C) replaced by U.
pass all these video ids to Videos: list with part=statistics
sort on your side all the video commentCounts

Related

Getting a list of all Media in Instagram with Graph API

In my code, I have been pulling the list of media in Instagram using the following URL:
https://graph.facebook.com/{app_id}/media?fields=media_url,{..some fields here...}&limit=10000&access_token={my_access_token}
This was working fine and I didn't touch the code for a month. Now suddenly it gives the error:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (media) on node type (Application)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Aty4vnPpLWfGq9Hj6hQFtZR"
}
}
Nothing in the documentation says that media is no longer available. Graph API version has updated from v14 to v15 since I used it, but the request isn't working on either version.
Access token is fine because other requests are working correctly.
Does anyone have any insights? What alternatives do I have?
I think you are defining an invalid field. Below is a list of fields you can use. Also i suggest you also try instagram account id instead of app_id.
fields=[id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count]
final url:
https://graph.facebook.com/v14.0/{instagram_account_id}/media?fields=id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count&access_token={my_access_token}

How to filter tweets for bots and influential account or account of interest using twitter v2 api

I am using twitter v2 apis for getting the count and tweets. I am trying to fetch tweets based on some hashtag. I want to filter the tweets on some criteria before fetching them so that I can save the allowed quota. The documentation says that I can use followers_count or listed_count or filter the bots using -bio:bot -bio_name:bot -bio_location:bot -bio:TwitterBot -bio_name:TwitterBot -bio_location:TwitterBot but the api response for these filters is invalid operator.
How can I use these operators in v2 api to filter the tweets?
POST EDITED:
so my request where I use followers_count is like this
https://api.twitter.com/2/tweets/counts/all?query=(%23bitcoin OR %23BTC) lang:en -is:retweet -is:reply -is:quote -is:nullcast followers_count:5000&start_time=2022-03-01T00:00:00Z&granularity=day
The response is
{
"errors": [
{
"parameters": {
"query": [
"(#bitcoin OR #BTC) lang:en -is:retweet -is:reply -is:quote -is:nullcast followers_count:5000"
]
},
"message": "There were errors processing your request: Reference to invalid operator 'followers_count'. Operator is not available in current product or product packaging. Please refer to complete available operator list at https://developer.twitter.com/en/docs/twitter-api/enterprise/rules-and-filtering/operators-by-product. (at position 73)"
}
],
"title": "Invalid Request",
"detail": "One or more parameters to your request was invalid.",
"type": "https://api.twitter.com/2/problems/invalid-request"
}
I get similar response for using bot query like -bio:bot -bio_name:bot -bio_location:bot -bio:TwitterBot -bio_name:TwitterBot -bio_location:TwitterBot or listed_count.
If I remove these operators, the api works fine.

YouTube Data API V3 unkownPart "localizations"

I have been trying to fetch all videos from a playlist using YouTube Data API, which worked like a char; next, I wanted to try and filter videos based on languages, so I wanted to try to include the "localizations" part. However, whenever I do, I get a 400 response stating that "localizations" is "unkownPart". From what I could see in the documentation, I should have my GET request structured properly:
`https://youtube.googleapis.com/youtube/v3/playlistItems?part=localizations&part=snippet&maxResults=${limit}&playlistId=${playlistId}&key=${apiKey}`
Error message in postman:
{
"error": {
"code": 400,
"message": "'localizations'",
"errors": [
{
"message": "'localizations'",
"domain": "youtube.part",
"reason": "unknownPart",
"location": "part",
"locationType": "parameter"
}
]
}
}
"localizations" is a direct copy from the documentation. The GET request works fine if I remove it so I'm confident that the problem is either the order or my parameters, or the combinations of parameters in use (though I couldn't find anything about incompatible parameters in the documentation).
Parameters order goes as follows:
localizations
snippet
playlistId
key
EDIT: link to the documentation: https://developers.google.com/youtube/v3/docs/playlists/list
After sending the Issue Report it was discovered that I had been using the wrong API endpoint. Somehow (I can't remember why) I was using the "playlistItem" endpoint which doesn't support "localizations", and needed to shift to using the "playlists" endpoint instead.
Furthermore when using a combination of both "snippet" and "localization", they should be within the same parameter but comma-separated, however, Postman doesn't auto-convert the commas in the parameters to "%2C" and therefore would cause further trouble understanding the requests. Fixing these 2 steps, it now works as intended.

Youtube API V3, search , publishedAfter, invalidSearchFilter

I'm just trying to make a search over youtube for my own videos that publisher after X date
However when i use publishAfter parameter, it's giving invalidSearchFilter error even of i set type parameter as video.
Error description is like this:
The request contains an invalid combination of search filters and/or restrictions. Note that you must set the type parameter to video if you set either the forContentOwner or forMine parameters to true. You must also set the type parameter to video if you set a value for the eventType, videoCaption, videoCategoryId, videoDefinition, videoDimension, videoDuration, videoEmbeddable, videoLicense, videoSyndicated, or videoType parameters.
You can reproduce this error from: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&forMine=true&publishedAfter=1970-01-01T00%253A00%253A00Z&type=video&_h=11& (after login via oauth 2.0)
Any idea what can i do in this situation?
I used the link that you provided. The problem is not the date. The problem is the conflicting search restrictions that you used. To make your search work, leave the "forMine" parameter empty so it doesn't conflict with your date filters and possibly the 'q' parameter as well. Do that and it will work.
Also, you have to specify the channelID to specify it's yours. Give it a try
I am trying to work on a task to retrieve all the videos from our own channel, my problem with using forMine filter was, I was passing channelId filter alongside forMine filter (which actually does not make sense, if I am saying to get my own data then I should not pass channel id explicitly, so I blame myself for that), which was returning as an error saying that Request contains an invalid argument.
Here is what my request was when it was causing the error:
curl --location -g --request GET 'https://youtube.googleapis.com/youtube/v3/search?part=snippet,id&channelId=[Channel ID]&forMine=true&order=date&type=video&key=[API KEY]&maxResults=25' \
--header 'Authorization: Bearer [ACCESS TOKEN]' \
--header 'Accept: application/json'
And this was the JSON return:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
As soon as I removed the channelId query parameter, the error went away.

Quota Limits For You-Tube Data API V3?

The new Google Developers console shows the following limit for YouTube Data API v3:
PER USER LIMIT 2 requests/second/user
Whereas the old Google Developers console shows:
2.0 units/second/user
(i.e. one is requests per second, the other is units per second which are quite different).
From - https://developers.google.com/youtube/v3/determine_quota_cost - the Search request appears to have a cost of 200 units, if the latter case above is correct would this mean we can only make one of these requests every 100 seconds?
This does seem to tie in more closely with what we are experiencing which is regular occurrences of the following 403 forbidden error after paging through only a few results from a YouTube search:
"error": {
"errors": [
{
"domain": "youtube.quota",
"reason": "quotaExceeded",
"message": "Quota Exceeded"
}
],
"code": 403,
"message": "Quota Exceeded"
}
}
The new console is right on this point. It's request/sec.
But you may have been hitting daily quota limits.
Remember that in many cases, you can substitute a less costly call, such as youtube.videos.list, in place of the youtube.search.list method. For example, to search most popular videos instead of the search.list call, you can use the videos.list call using the most popular chart.
you can contact youtube and apply for higher quota or pay for higher quota

Resources