YouTube Analytics - when to stop querying? - youtube-api

A quick overview of what my application is doing:
A customer authenticates their Google account via OAuth.
I retrieve their access and refresh tokens and store them for use
I make a YouTube Analytics report query for basic metrics such as views, comments, etc.. I query starting from today, and go backwards in time.
My question is: How do I know when to stop querying?
The API doesn't appear to return any errors even if I specify a date from 1980. The API does seem to return no results in that the "rows" field is not present:
{"kind":"youtubeAnalytics#resultTable","columnHeaders":[{"name":"day","columnType":"DIMENSION","dataType":"STRING"},{"name":"views","columnType":"METRIC","dataType":"INTEGER"}]}
Is it reliable for me to stop querying if the API returns a result like this where the "rows" field is not-present? My concern is if the customer doesn't have any data for a certain period, and the API returns this type of result (missing "rows" field), is it possible that the customer still has data prior to his time period? Thus I should continue querying backwards? How do I know when to stop?

YouTube launched in February 2005, so you at least never have to query for dates before that :)
However, it seems like days without any views will return 0 views, and days before a video or channel existed will not return a row, so you should be safe to stop when no more rows are returned.
But instead of querying day by day, why don't you query for the whole date interval you are interested in and thus only make one query? With start-date=2005-01-01 and end-date={$today} and dimensions=day?
My video that recently got uploaded, with very limited number of views:
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DYHMS8hN8s49F93iJuEgG6w&start-date=2005-01-01&end-date=2013-01-21&metrics=views%2Ccomments&dimensions=day&filters=video%3D%3D_iwmv6644dA&sort=day&key={YOUR_API_KEY}
Response:
{
"kind": "youtubeAnalytics#resultTable",
"columnHeaders": [
{
"name": "day",
"columnType": "DIMENSION",
"dataType": "STRING"
}, {
"name": "views",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"rows": [
["2013-01-07", 1],
["2013-01-08", 0],
["2013-01-09", 0],
["2013-01-10", 0],
["2013-01-11", 0],
["2013-01-12", 1],
["2013-01-13", 0],
["2013-01-14", 1],
["2013-01-15", 0],
["2013-01-16", 0]
["2013-01-17", 0],
["2013-01-18", 0],
["2013-01-19", 0],
]
}
btw, I used the API Explorer to try this out: https://developers.google.com/youtube/analytics/v1/

Related

Start chart from threshold

Current implementation:
Desired implementation:
If you look carefully there is a vertical line connecting threshold with the first point of my displayed chart. Any ideas how to implement it ? What I thought was to get the threshold price (got it)and find a way to insert it a starting point, but I struggle a bit (since i use unix timestamp).Thanks in advance !
I parse the data from Monday to Friday, but I only display Intraday's data (let's say I am o Friday now). So the threshold will be the closing price from Thursday.
You are right. Inserting a starting point seems to be the best solution for that. You can do it as below:
const threshold = 10;
const data = [
[20, 11],
...
];
data.unshift([data[0][0], threshold]);
Highcharts.chart('container', {
series: [{
type: 'area',
threshold,
data
}]
});
Live demo: http://jsfiddle.net/BlackLabel/7ynzhmuv/
API Reference: https://api.highcharts.com/highcharts/series.area.threshold

Microsoft Graph - FindMeetingTimes API error?

I am seeing issues with the Graph API method findMeetingTimes.
As you can see from the attached file the API response differs depending on the start time. When using flat times like 12:00 the response includes only flat times - while when using non-flat times like 12:15 it only includes 'half-hour times'.
)
So to get all possible meeting times I would have to make at least two API calls, which doesn't seem very practical.
Is there something I am missing ?
Thanks in advance,
Jacky
No, you are not missing anything. You'll need to call the API more than once to get suggestions with overlapping times.
The API returns the nearest available time to the start time specified in the request. The suggestions will always be on the hour or at half past.
Thereafter, it will give suggestions with increments of 30 minutes, or value specified in the meetingDuration property from the first suggestion, without overlaps.
If you had set your start time to say, 12:15 and the first available time is 13:00 and meeting duration is 1h, all suggestions will be on the hour. The same applies if you'd set the start time to 12:00 and the first available time is at 12:30, all suggestions will be at half past.
You can add the returnSuggestionReasons property in your request which gives an explanation on why a particular time was suggested.
{
"timeConstraint": {
"activityDomain": "unrestricted",
"timeSlots": [
{
"start": {
"dateTime": "2021-05-24T12:00:00",
"timeZone": "UTC"
},
"end": {
"dateTime": "2021-05-24T18:00:00",
"timeZone": "UTC"
}
}
]
},
"meetingDuration": "PT30MIN",
"returnSuggestionReasons": "true"
}

In snowflake how to get the date as i wanted format in snowflake

I have been facing the issue while retrieving year from snowflake table.
My table has value as below:
year :20
day:10
month :02
I need to dob value as 2020-10-02. When I am using the concat_ws I'm getting expected result, however the padded with 00 the dob printed like 0020-10-02.
Also when we have 99 in the year column then while retrieving it should display 1999
I have created query as below:
select to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'MM/DD/YYYY') from XXX;
Suggest me if any functions also.
Take a look at this
YY
Two-digit year, controlled by the TWO_DIGIT_CENTURY_START session parameter, e.g. when set to 1980, values of 79 and 80 parsed as 2079 and 1980 respectively.
select TO_DATE('99-10-02','YY-MM-DD');
There's no way to have automagically the "right" year display before, if some of your users are going to be very young and others very old, how could you know for sure if the person was born in 20th or 21st century?
I didn't quite get how your data is stored, so I'll assume a json structure since it appears in your query.
set json = '{
"elements": [{
"year": "01",
"month": "02",
"day": "10"
}, {
"year": "99",
"month": "02",
"day": "10"
}, {
"year": "20",
"month": "02",
"day": "10"
}]
}'::varchar;
Now I'll parse the json, extract the values, putting that here so you can make sure we're having the same data structure.
CREATE OR REPLACE TEMP TABLE test AS
select t2.VALUE: day::varchar dob_day,
t2.VALUE: month::varchar dob_month,
t2.VALUE: year::varchar dob_year
from (select parse_json($json) as json) t,
lateral flatten(input => parse_json(t.json), path => 'elements') t2
Now is the part that will interest you. It is dirty trick and assumes that if the two digit year is higher than the current two digit year, then it cannot be 2000, but instead 1900.
SELECT to_date(concat_ws('-',
IFF(t2.dob_year > RIGHT(extract(year, current_timestamp), 2), '19'||t2.dob_year , '20'||t2.dob_year ),
t2.dob_month,
t2.dob_day)) proper_date
FROM test t2;
Change the date format in your to_date to 'YY-MM-DD' should give you DOB you want, and I suggest to use try_to_date if you suspect data issues as it will NULL the field if not a valid date.
NOTE if you are using US formatting then use YY-DD-MM (the month in the end)
select to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD') from XXX;
Also, if you want to safely check that the DOB is not in future then add IFF as follows
IFF(CURRENT_DATE > to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD'), to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD'),NULL);

HighStock Chart x-axis end point

I have a series of JSON which starts at 8am and throughout the day it updates my graph as time goes by until 5pm. The problem is I do not want to return data from my api until 5pm. Instead I would like to set my graph to always have from 8am-5pm on the x-axis, I've played around with tickPositioner but to no avail.
So in summary this data displays fine:
{
"d": [
[
1483689600000,
7195.31
],
[
1483689900000,
7188.45
],
[
1483690200000,
7184.38
],
[
1483690500000,
7185.82
]] }
But I do not want to have to return the following in my api [ 1483690500000, null ] etc etc for the remainder of the day, I just want to have the end time (5pm) being set in the javascript if this is possible?

Undeterministic search results with most viewed

I would like to use the Youtube data API search to retrieve the most viewed videos on Youtube. However, for some reason, my results are missing some videos.
Here is the API call: https://www.googleapis.com/youtube/v3/search?part=snippet&key={YOUR-API-KEY}&alt=json&type=video&order=viewCount&maxResults=50
The 13 first results returned by the API are:
9bZkp7q19f0
RgKAFK5djSk
fRh_vgS2dFE
OPf0YbXqDm0
e-ORhEE9VVg
KYniUCGPGLs
YQHsXMglC9A
nfWlot6h_JM
NUsoVlDFqZg
HP-MbfHFUqs
CevxZvSJLk8
7PCkvCPvDXk
0KSOMA3QBU0
These should be the 13 most viewed videos on Youtube at the time I queried it.
However, looking at this Youtube-made playlist:
https://www.youtube.com/playlist?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC
I can see that the video YqeW9_5kURI, which has 1.7 billion views, should arrive in 9th position in the list returned by the API, but it doesn't. Actually, it never appears among the 500 (max) videos returned by the API.
UPDATE
Since results change every day, I did more comprehensive tests with the search API.
Here is the result of the API call I mentioned above from yesterday dec. 13th (first 10 results):
9bZkp7q19f0
RgKAFK5djSk
fRh_vgS2dFE
OPf0YbXqDm0
e-ORhEE9VVg
KYniUCGPGLs
YQHsXMglC9A
nfWlot6h_JM
NUsoVlDFqZg
HP-MbfHFUqs
And here is the result obtained today, dec. 14th (again, first 10 results):
9bZkp7q19f0
RgKAFK5djSk
fRh_vgS2dFE
KYniUCGPGLs
nfWlot6h_JM
NUsoVlDFqZg
YqeW9_5kURI
HP-MbfHFUqs
CevxZvSJLk8
09R8_2nJtjg
I am absolutely sure that the API call did not change between these two dates, code is exactly the same.
First anomaly: video 7 in second call (YqeW9_5kURI) does not appear in first call (this was my original post example), although its 1.7 billion views were definitely not done overnight.
Second anomaly: videos 4, 5, 7 in first call (OPf0YbXqDm0, e-ORhEE9VVg, YQHsXMglC9A) do not appear in second call, although they are still available on Youtube and still more viewed than video 5 (nfWlot6h_JM), for instance.
These anomalies repeat very often over larger sets of results.
To sum up, the search API does not seem to yield deterministic results with no query string and viewCount order, is this expected behaviour?
Or can you help me figure out what could be the reason for this?
Thanks in advance for your help, any pointers will be greatly appreciated.
Try to include filtering parameters like chart. The chart parameter identifies the chart that you want to retrieve. mostPopular retruns the most popular videos for the specified content region and `video category.
If successful, this method returns a response body with the following structure:
{
"kind": "youtube#videoListResponse",
"etag": etag,
"nextPageToken": string,
"prevPageToken": string,
"pageInfo": {
"totalResults": integer,
"resultsPerPage": integer
},
"items": [
video Resource
]
}

Resources