YouTube API. How to get approximate quantity of results? - youtube

I am interested in number which represents approximate number of results for some defined search parameters. It is presented on the picture below as "About N results".
Is it possible to get this somehow?
PS. I am using Java for android app.

Videos.search returns a response body which looks like this.
{
"kind": "youtube#searchListResponse",
"etag": etag,
"nextPageToken": string,
"prevPageToken": string,
"regionCode": string,
"pageInfo": {
"totalResults": integer,
"resultsPerPage": integer
},
"items": [
search Resource
]
}
I think the closest you are going to get is going to be totalResults. Which I really doubt will be that large.
I just did a dummy search with basically asking for everything and it returned
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
The max rows you will get back from a search from the API is 1000000 google is not going to tell you how much a search on the website would return. So the answer to your question is there is no way to return the actual value the website would return via the API.

Related

KSQL for aggregated historic data sorted by day with accepting late updates

i've been trying to use ksql to aggregate data that comes in the following json pattern.
{"code": "1234", "type": "1234", "item": "1234", "items_sold": 3, "items_acquired": 0, "timestamp": "yyyyMMddhhmmssSSSSSSSSS"}
So far I've managed to aggregate the net change of items for any given day. I can also output the total current amount for any given item of type and code without problems.
The following is how i calculate net change for a given day
CREATE STREAM daily_change WITH (KAFKA_TOPIC='daily_change', PARTITIONS=1, REPLICAS=1) AS SELECT
items_acquired - items_sold as net_change,
item, type, code,
SUBSTRING(CAST(datets AS STRING), 0, 8) as curr_day
FROM change_event
EMIT CHANGES;
and from that stream i create a table
CREATE TABLE DAILY_INVENTORY WITH (KAFKA_TOPIC='daily_inventory', KEY_FORMAT='DELIMITED', PARTITIONS=1, REPLICAS=1, VALUE_FORMAT='JSON') AS SELECT
SUM(net_change),
curr_day, item, type, code
FROM daily_change
WINDOW TUMBLING ( SIZE 24 HOURS )
GROUP BY curr_day, item, type, code
EMIT CHANGES;
For the total inventory its the following
CREATE TABLE current_inventory WITH (KAFKA_TOPIC='current_inventory', KEY_FORMAT='DELIMITED', PARTITIONS=1, REPLICAS=1, VALUE_FORMAT='JSON') AS SELECT
SUM(items_acquired - items_sold) current_stock,
code, item, type
FROM change_event
GROUP BY code, item, type
EMIT CHANGES;
I'm stuck trying to get a table to show the total amount of inventory grouped by the day, code, item and type.
On top of that problem, it also needs to accept changes of up to 14 days in the past.
The problem is that i have not managed to seperate the inventory by day. It either calculates only the net change of amount per day or the total current amount.
Basically either i do not have the information of day or i do not have the information of total amount.
Some example data so i can illustrate the problem:
{"code": "1234", "type": "1234", "item": "1234", "items_sold": 0, "items_acquired": 2, "timestamp": "20220910113045000000000"}
{"code": "1234", "type": "1234", "item": "1234", "items_sold": 1, "items_acquired": 0, "timestamp": "20220910143045000000000"}
At the end of the day this should result in a total of 1 for 20220910
{"code": "1234", "type": "1234", "item": "1234", "items_sold": 0, "items_acquired": 3, "timestamp": "20220912113045000000000"}
This should give me a total of 4 for 20220912
{"code": "1234", "type": "1234", "item": "1234", "items_sold": 0, "items_acquired": 1, "timestamp": "20220902113045000000000"}
This should adjust every total by 1, so 20220910 should now be 2, and
20220912 should now be 5.
I've tried using windowing with retention and grace and such, but haven't had success, as mentioned above i either end up producing the net_change or have to give up the information of the day timestamp
Does anybody have an idea what kind of approach i could try?

Google Sheets API v4 - bold part of cell

When manually editing a Google Sheet, I notice that you can make part of a cell bold by simply highlighting a portion of the text and clicking the 'bold' button.
Is there way to achieve this same behavior using the API v4? I cannot seem to find anything in the documentation https://developers.google.com/sheets/api
I think that "TextFormatRun" with spreadsheets.batchUpdate in Sheets API can be achieved your goal.
As the sample situation, it supposes that the cell "A1" on the Spreadsheet has the value of hi i'm bold - and I'm not and you want to do the bold type hi i'm bold of hi i'm bold - and I'm not.
In this case, the following endpoint and request body can achieve this.
Endpoint:
https://sheets.googleapis.com/v4/spreadsheets/###spreadsheetId###:batchUpdate
Request body:
{"requests": [
{"updateCells": {
"range": {"sheetId": "###sheetId###", "startRowIndex": 0, "endRowIndex": 1, "startColumnIndex": 0, "endColumnIndex": 1},
"rows": [{"values": [{"textFormatRuns":[
{"format": {"bold": true}, "startIndex": 0},
{"format": {"bold": false}, "startIndex": 11}
]}]}],
"fields": "textFormatRuns.format.bold"
}}
]}
When you use this, please set the Spreadsheet ID and sheet ID.
References:
Method: spreadsheets.batchUpdate
TextFormatRun
If I misunderstood your question and this was not the direction you want, I apologize.

youtube.search.list does not return any items after 9 pages

I want to get a list of many youtube Channels.
After i got around 400 results (8 pages x 50 results/page), i call the 8th oder 9th page via:
GET https://www.googleapis.com/youtube/v3/search?part=id&maxResults=50&pageToken=CJADEAE&type=channel&key={YOUR_API_KEY}
i get only 16 results and from this point on the next 10 (or something) nextPageTokens return no items at all and after the 19th nextPageToken there is not even a nextPageToken in the response.
Nevertheless the query says "totalResults": 1000000, "resultsPerPage": 50.
Is this a bug or am I doing something wrong?
The serch call is restricted. As it will start to return duplicates after a while, and it is almost an infinite number of possible results. So they have chosen to cap that search term.

Create/Modify Survey - API v3

I have used V2 of the Survey Monkey API to get details on collectors and surveys. I am now interested in learning how to use the V3 API to Create/Modify surveys. I hope some useful tips from other users, would help me out, as I am relatively new to the API. I will be using Python.
Specifically, my use case is that I want to use a base survey as a template, and modify the answer options per recipient. Here is an example:
Recipient A would get:
Q1. On a scale of 1 (least) to 5 (most), how much do you like eating:
a. Burgers
b. Pizza
c. Hotdogs
Q2. On a scale of 1 (rarely) to 5 (very), in a typical week, how often do you eat:
a. Burgers
b. Pizza
c. Hotdogs
While recipient B would get
Q1. On a scale of 1 (least) to 5 (most), how much do you like eating:
a. Fried chicken
b. French fries
c. Tacos
Q2. On a scale of 1 (rarely) to 5 (very), in a typical week, how often do you eat:
a. Fried chicken
b. French fries
c. Tacos
How do I create the API that reads in the various answer options.
I also plan to use pandas to load the table of answer options per recipient, and want to find out how to pipe the answer options into the API - would it be through a conversion into JSON? Have read the documentation, but it's not always obvious what needs to be done (to a newbie).
Thanks so much!
As far as I'm aware, there isn't branching logic available to show/hide answer options. If you were sending the survey to one recipient at a time, and you really wanted to have one question with modified answer options you could theoretically do something like this:
POST /v3/surveys/<id>/pages/<id>/questions
{
"family": "matrix",
"subtype": "rating",
"answers": {
"rows": [
{
"text": "Burgers",
"visible": true,
"position": 1
},
{
"text": "Pizza",
"visible": true,
"position": 2
},
{
"text": "Hotdogs",
"visible": true,
"position": 3
},
{
"text": "Fried chicken",
"visible": false,
"position": 4
},
{
"text": "French fries",
"visible": false,
"position": 5
},
{
"text": "Tacos",
"visible": false,
"position": 6
}
],
"choices": [
{
"text": "1",
"position": 1
},
{
"text": "2",
"position": 2
},
{
"text": "3",
"position": 3
},
{
"text": "4",
"position": 4
},
{
"text": "5",
"position": 5
}
]
},
"headings": [
{
"heading": "On a scale of 1 (least) to 5 (most), how much do you like eating:"
}
],
"forced_ranking": false
}
And then patch visible on the answer options between true and false for each recipient, that way you can analyse on the same question. But that's not really ideal as this changes the survey for everyone taking it limiting you to one recipient taking the survey at a time.
Given you are planning on moving the data to pandas anyways, why not just separate into four different questions? Then just use advanced branching to hide/show questions based on a custom value on the recipient. That way you can have a rule that's something like:
if contact.custom1 is exactly "fried" then hide question 1 and show question 2
Then you can export all your data or fetch your responses through the API
GET /v3/surveys/<id>/responses/bulk
Which will give you a JSON of all the responses which you can move to pandas. There may be other ways to do what you'd like but given the available functionality; this is a couple examples that may be helpful.

Group data by timeframe on a datetime Highcharts graph

Consider the following series:
[
{
"x": 1447840800000,
"y": 199214,
"num_messages": 6
},
{
"x": 1447842600000,
"y": 27152,
"num_messages": 3
},
{
"x": 1447844400000,
"y": 349919,
"num_messages": 7
}
...
]
Each of the timestamps are a half-hour apart. I'm currently showing 2-weeks worth of data like this on a datetime-formatted Highcharts column chart. I would like to give users the ability to view it in different increments of time, not just the default half-hour. When larger increments are chosen, the y and num_messages values should be summed for whichever data points fall within a given increment.
Currently, I am manipulating the series array manually to create a new series with the desired time increments. But can Highcharts essentially do this for me? Tried googling and looking through the API but didn't come up with anything.

Resources