Datetime format started_at and ended_at PHP problem

Hello, i have a problem with the datetime format, i have this error :
“Bad Request” status 400
Message : "parsing time “2018-10-04T18:27:28 00:00” as “2006-01-02T15:04:05Z07:00”: cannot parse “” as “Z07:00"”

My test code for 1 day of clips range :

$started_at = date('Y-m-d\TH:i:sP');
$ended_at = date('Y-m-d\TH:i:sP', strtotime($started_at . ' -1 day'));
$game_id = "65632";
GetAPI_clips($game_id,$started_at,$ended_at,$lang);

Thank you

Date needs to be formatted as per RFC3339

The error you are getting is a PHP error not a TwitchAPI error, I believe.

You are also setting ended at to before started at. Which is back to front.

Try this instead:

$started_at = date(DATE_RFC3339, time() - 86400);
$ended_at = date(DATE_RFC3339);

Yes RFC3339 is Y-m-d\TH:i:sP too, i tested your two lines but not working. I have this :
{"error":"Bad Request","status":400,"message":"parsing time \"2018-10-03T22:09:37 02:00\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"\" as \"Z07:00\""}

I know is not good but is working on this :
$started_date = date(‘Y-m-d’, strtotime($started_at . ’ -1 day’));
$ended_date = date(‘Y-m-d’);
$started_at = $started_date.“T00:00:00Z”;
$ended_at = $ended_date.“T00:00:00Z”;

Please provide all the code and/or the actual request you are making to Twitch API

My request : ‘https://api.twitch.tv/helix/clips?game_id=’.$game_id.’&started_at=’.$started_at.’&ended_at=’.$ended_at.’&first=100&language=’.$lang;

I think it’s the format of the date that is not good, I try two formats but it still does not work.

Exemple with : echo date(DATE_RFC3339);
Output : 2018-10-04T22:21:59+02:00

I think Twitch not like “+02:00” ?

You need to URLencode your parameters

https://api.twitch.tv/helix/clips?game_id=’.$game_id.’&started_at=’.urlencode($started_at).’&ended_at=’.urlencode($ended_at).’&first=100&language=’.$lang;

As the + is being interpreted as something else and Twitch is not receiving a RFC3339 date from you.

1 Like

Obviously you are a genius! Thank so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.