when I make request to get playlist items, I get only 5 items from the playlist.
But they were much more.
who knows how to disable this restriction?
request
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PL7W7Mm4SA4uNAsS33fh3HPlN7ffx7ZdMN&key=mykey
You need to set the maxResults parameter to whatever you like (max is 50):
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PL7W7Mm4SA4uNAsS33fh3HPlN7ffx7ZdMN&key=mykey&maxResults=50
Additionally, you should check whether your result has the nextPageToken item. If so, make another request with the parameter pageToken set to the value of nextPageToken. Repeat this until there's no more nextPageToken item.
Related
I am trying to get a list of my subscribers using the Subscriptions: list. Is there a way to get values for all of my subscribers, or is it only possible to get 50 max? Is there another way to get values for all of my subscribers? I am aware the documentation says you can only get 50 results max, but I wanted to see if there was another way to get all the values. Thanks!
The max results you can get with 1 call is 50.
To get more results, you would need to make multiple calls. After the first call finishes and there are more results that can be obtained, the API call should return a string for the nextPageToken property. Use this for the optional pageToken parameter for your next API call. Repeat this process until you've obtained all the results.
Yes! Take a look at the pageToken parameter listed in the docs:
The relevant description is:
The pageToken parameter identifies a specific page in the result set that should be
returned. In an API response, the nextPageToken and prevPageToken properties identify
other pages that could be retrieved.
I am using Youtube Api to get all videos details of channel
https://www.googleapis.com/youtube/v3/search?part=snippet,id&key=XXXXXXXX&channelId=UCq-Fj5jknLsUf-MWSy4_brA&order=date&maxResults=50
You can see response
In the first response, I can see there are 761525 results and nextPageToken is also there but using that next page token I can max 300 to 400 video details after that API not giving me any result.
So is there any other to get all the videos details? Or anything is missing by me?
YouTube returns a soft limit of 500 videos for any search request.
If there are more than that in totalResults, you can split the search query using the publishedAfter and publishedBefore filters to loop through dates by day/week/month etc., making sure each 'time window' returns less than the 500 limit. Eventually, you will get all results.
After the first time you request an API call, for example this:
https://www.googleapis.com/youtube/v3/search?part=snippet,id&key=XXXXXXXX&channelId=UCq-Fj5jknLsUf-MWSy4_brA&order=date&maxResults=50
You need to fetch the nextPageToken parameter of that (1st) result , and feed it to the next (2nd) request. Let's suppose the nextPageToken of the first result is ABCDEFG, your next request must be like this:
https://www.googleapis.com/youtube/v3/search?part=snippet&pageToken=ABCDEFG,id&key=XXXXXXXX&channelId=UCq-Fj5jknLsUf-MWSy4_brA&order=date&maxResults=50
See that after snippet I've added &pageToken=ABCDEFG. And then you take again the string of the parameter nextPageToken of this (2nd) result and feed it to your next (3rd) request. So you need to do this with a while loop until the nextPageToken is null, which means you've hit the border number (in your case 761525 results). Or you can fix this by a certain number of results that you get.
Summary:
Request your first API call
Make a loop
Take the nextPageToken value
For your next requests, add after snippet this part &pageToken=
Write the value of nextPageToken after &pageToken=
Repeat from step 2 until a certain condition (until you get all the results or just a certain number of results)
Good day. I'm trying to get the top videos for gaming within the specified publish dates ordered by view count. I'm having a problem with the number of items that it is returning in the JSON response because it's less than 50 items even though I have set the maxResults parameter to 50 and the JSON response returns pageInfo.resultsPerPage equal to 50. The pageInfo.totalResults also returns a lot more than 50 so it should be displaying 50 items in the result. As an example, I'm using the followng URL
https://www.googleapis.com/youtube/v3/search?key={API_Key}&part=snippet&maxResults=50&order=viewCount&publishedAfter=2017-02-01T00%3A00%3A00Z&publishedBefore=2017-02-01T00%3A01%3A59Z&type=video&videoCategoryId=20
The returned result here the last time I ran this query has 20 items even though there are 161,307 total results. I would like to ask a solution that will make sure that I will always get the number of items equal to the maxResults if possible. Hope someone can help me on this. Thank you very much.
EDIT: I know how to use the page token, but I'm not aiming for getting the items that I need for more than one request (as the Data API have limited credits per day). The issue that I'm trying to resolve is to make sure that I always get 50 items everytime I invoke the request.
Although there are 160k+ total results, your publishedAfter/publishedBefore filters cut the number returned down to the videos published in that time range, which is 20.
Well, I got 50 results with the URL request that you provided. Just make sure that you place right value on the parameter that you use, especially the value in publishedAfter. You can also use the parameter pageToken to get the next page or next 50 results.
For more information, check this SO question on how to use pageToken
I'm trying to load the first 100 videos of a YouTube channel and I can only load 50 videos. I always get this error message
Max-results value is too high. Only up to 50 results can be returned per query.
and I'm using this URL.
http://gdata.youtube.com/feeds/api/users/shaytards/uploads?&max-results=100
I'm not sure if I need any kind of developer key to load 100 results. Even if you know a way to load videos 75-100 would be great but any help would be appreciated.
The Youtube data API requires you to set up your own pagination if you need to get more than 50 results. In this case, then, you would set max-results to 50 and do the query, then on your page have some sort of "next" button (or however you want to implement your pagination) that would trigger a new call (either through ajax, a new page, or whatever your own workflow is). This new call would be to the same data feed, but you'd append the parameter &start-index=51 so that you'd get 50 more results, numbered 51-100. You can continue on like this up to 1000 results.
See https://developers.google.com/youtube/2.0/reference#Paging_through_Results for more details.
In the YouTube Data API V3 it is a little different. Each search query returns a "nextPageToken" that can be used in a subsequent query for more results. Documentation: https://developers.google.com/youtube/v3/guides/implementation/pagination
I'm using the Twitter API atom format
http://search.twitter.com/search.atom?q=Name&:)&since:year-month-date&rpp=1500
but it's only returning 100 tweets, I tried using the JSON format as well, but it only returned 100 results. Is there anything that I'm doing wrong to only get 100 results?
Yes, you're limited on the number of results per page. In order to get more results, you have to use the page parameter like so:
http://search.twitter.com/search.atom?q=Name&:)&since:year-month-date&rpp=1500&page=2
EDIT
rpp: the number of tweets to return
per page, up to a max of 100. E.g.,
http://search.twitter.com/search.atom?lang=en&q=devo&rpp=15
page: the page number to return, up to
a max of roughly 1500 results (based
on rpp * page)
Source: http://search.twitter.com/api/
In other words your rpp won't work as you expect because the max is 100.
My sugestion.
Make a request to your API and retrieve 100 results by time.
Use a loop to check if your result count is set to 100.
if true, do a new request to page 2.
test again and check the number of itens until the resultset is lower than 100.
The Twitter Search API has changed, including in the naming of the parameters: for instance, rpp is now count and the page parameter was removed in favor of max_id, a parameter based on a timeline concept:
"To use max_id correctly, an application’s first request to a
timeline endpoint should only specify a count. When processing this
and subsequent responses, keep track of the lowest ID received. This
ID should be passed as the value of the max_id parameter for the next
request, which will only return Tweets with IDs lower than or equal to
the value of the max_id parameter."
https://developer.twitter.com/en/docs/tweets/timelines/guides/working-with-timelines
The updated link to the Twitter search api is:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
Remember that not all tweets are indexed and if you are using the non-commercial version, you are limited to a 7-day search.