Get most viewed clips of the week

Hello,

I want to get the most viewed clips of the week. So I tried it with the parameter started_at, but I get this result:

{"error":"Bad Request","status":400,"message":"parsing time \"2020-05-11T00:00:00 02:00\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"\" as \"Z07:00\""}

why? code is :

$date = date('c', strtotime('2020-05-11 00:00:00'));

$headers = [
	'Client-ID: '.$clientid,
	'Authorization: Bearer '.$access_token,
];
$handle = curl_init('https://api.Twitch.tv/helix/clips?broadcaster_id=XXX&started_at='.$date);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($handle);

can someone help me?

Z means Zulu as in +/- Nothing

2006-01-02T15:04:05Z07:00

should be

2006-01-02T15:04:05%2b07:00

So what to change ? If I output the $date I get it with T:

2020-05-011T00:00:00+02:00

You need to url encode that, as a + is a space. so you have to URL encode the + to %2b

$handle = curl_init('https://api.Twitch.tv/helix/clips?broadcaster_id=XXX&started_at='.$date);

becomes

$handle = curl_init('https://api.Twitch.tv/helix/clips?broadcaster_id=XXX&started_at='.urlencode($date));

And

$date = date('Y-m-d\TH:i:sP', strtotime('2020-05-11 00:00:00'));

You need the RFC3339 format

https://www.php.net/manual/en/class.datetime.php

1 Like