2

I'm using the search.list API to display a single result on my site. This is the call:

const request = gapi.client.youtube.search.list({
  q: query,
  part: 'id',
  type: 'video',
  maxResults: '1'
});

After a few calls, I see around 1K queries in my Quotas dashboard:

enter image description here

But on the Metrics dashboard I see only 20 requests (which is correct). This means every request takes 50-100 units. How can I optimize this request to take less units? since I only need one result.

[Edit] Resolved. Check out the comment by @MauricioAriasOlave for the right query optimization.

shaym2
  • 87
  • 2
  • 11
  • @Andreas thanks, but it says there `A simple read operation that only retrieves the ID of each returned resource has a cost of approximately 1 unit` so I'm still not sure about this behaviour. I guess my question boils down to how to optimize the `search.list` query so it takes less units (currently ~50). I only need the first result. – shaym2 Jan 16 '19 at 09:33
  • Then maybe it's because you have multiple queries in the `q` parameter? – Andreas Jan 16 '19 at 09:38
  • @Andreas it's a simple string: `const query = 'adele'` – shaym2 Jan 16 '19 at 09:43
  • Also, I found this `Quota impact: A call to this method has a quota cost of 100 units.`, which is double of your current estimation – Andreas Jan 16 '19 at 09:45
  • @Andreas still, not sure why it's so much for getting a single result – shaym2 Jan 16 '19 at 12:48
  • @DalmTo I edited the question. Please remove the duplicate, since it doesn't answer the need to optimize the query. – shaym2 Jan 16 '19 at 12:53
  • @shaym2 can you use the [Google API Explorer](https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&maxResults=25&q=surfing) for create a try-it version of your request? I think I have a way to optimize your query, but I preffer added as an answer. – Mauricio Arias Olave Jan 16 '19 at 15:56
  • @MauricioAriasOlave sure, here it is: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=id&maxResults=1&q=surfing&type=video&_h=3& – shaym2 Jan 17 '19 at 12:19
  • 1
    @shaym2 since it seems I wont be able to post an answer my suggestion as follows: If you only need get the `videoId` of your search results, you can use this sample [I made using the Google API Explorer](https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&maxResults=1&q=surfing&fields=items%252Fid%252FvideoId&_h=2&). If you want more details in the search results, I advice you [edit] your question and add the specific details you want retrieve. – Mauricio Arias Olave Jan 17 '19 at 13:35
  • 2
    @MauricioAriasOlave Amazing, thank you. following your advice and adding **fields** to my query (which only differs from yours by requesting `id` instead of `snippet` in the **part**) reduced the query to 20 units. This is the chosen answer. – shaym2 Jan 17 '19 at 20:43
  • @shaym2 you welcome. I'm glad it worked for you. – Mauricio Arias Olave Jan 17 '19 at 20:55
  • 1
    It seems that Mauricio's suggestion does not work anymore. Can anyone check? I'm testing it here and facing the 100 units being consumed, always :( – andreybleme May 01 '20 at 22:53

0 Answers0