I Don't Know how to use Get Clips Helix Api

Hello , I Would like to Get Some Help on How to use this Twitch Api
To Get Last 7 days Top Clips For a Special Broadcaster as shown in the example .
It Dosen’t Return anything for me , & i’m not sure if i made a mistake in the Date Format for the proprieties Started_at & ended_at . in my example i did ?started_at=2020-03-01?ended_at=2020-03-08
to get clips between 1 MARS 2020 & 8 MARS 2020 .
Thanks for your help <3 :slight_smile:

Your URL is wrong.

It should be

clips?broadcaster_id=foo&started_at=date&ended_at=anotehrdate

Query string arguments need to be & separated in the URL

IT WORKED But i still have a problem with the Date Format ! i don’t know how to convert this date : 2020-03-01 to RFC3339

&started_at=2020-03-01T00:00:00Z&ended_at=2020-03-08T00:00:00Z

Thank Youuu :smiley: iT Worked :slight_smile: , is there any easy way to use this format in php because in my php script i should be using variables . is there any way to use Varibale like $date.time.now & convert it to this format ?? & substract 7 days from it in the second variable .

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

Suggests

Y-m-d\TH:i:sP

So

$date = date(‘Y-m-d\TH:i:sP’, time());

It Worked . Is It Possible to make another Date Variable and Substract 7 days from it ?

https://www.php.net/strtotime

$one_week = strtotime(‘-1 week’):


I think i have a problem with First date i should add some more “” i guess , and also the Format Need to be like this 2020-03-08T17:56:03Z i don’t know how to add that letter in the End

eventough i added the P $date = date(“Y-m-d\TH:i:sP”, time()); in the format it give me this !!
api6

Z means you are in UTC
+01:00 means you are in a timezone +1 of UTC

So +01:00 is correct

The P of the timezone in the format means “append the timezone offset”

P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)

https://php.net/date



I’m Not Sure why i’m still getting an error if the Date Format is Correct

You are not URLencoding your parameters

https://www.php.net/urlencode



I Tried This but i still i think i messed up with the dates

Please stop using screenshots for your code, makes it difficult for me to copy/paste/fix

You can just paste code into the forums, using the relevant formatting functions

$date1 = urlencode(date(‘Y-m-d\TH:i:sP’), time());
$date2 = urlencode(date(‘Y-m-d\TH:i:sP’, strtotime(‘-1 week’));

null

Am Sorry ,
It Still returning Null For me

<?php

$date1 = date("Y-m-d\TH:i:sP", time());
$date2 = date("Y-m-d\TH:i:sP", strtotime("-7 days"));
   $date3 = urldecode($date1);
   $date4 = urldecode($date2);
echo $date1;
echo "<br>";
echo $date2;
echo "<br>";
echo $date3;
echo "<br>";
echo $date4;
echo "<br>";

$ch = curl_init('https://api.twitch.tv/helix/clips?broadcaster_id=157527726&started_at=' . $date4 . ' &ended_at= '.$date3);

You need to urlencode. You have urldecoded

$date3 = urlencode($date1);
$date4 = urlencode($date2);


I Changed it , but still NULL

$date1 = date("Y-m-d\TH:i:sP", time());
$date2 = date("Y-m-d\TH:i:sP", strtotime("-7 days"));
$date3 = urlencode($date1);
$date4 = urlencode($date2);
echo $date1;
echo "<br>";
echo $date2;
echo "<br>";
echo $date3;
echo "<br>";
echo $date4;
echo "<br>";

$ch = curl_init('https://api.twitch.tv/helix/clips?broadcaster_id=157527726&started_at=' . $date3 . ' &ended_at= '.$date4);

When i Tried to use the Encoded Date Format in the Api , It Actually Worked

$ch = curl_init('https://api.twitch.tv/helix/clips?broadcaster_id=157527726&started_at=2020-03-01T18%3A42%3A52%2B01%3A00&ended_at=2020-03-08T18%3A42%3A52%2B01%3A00');


However It’s Not working when using Variables like this :

$ch = curl_init('https://api.twitch.tv/helix/clips?broadcaster_id=157527726&started_at=' . $date3 . ' &ended_at= '.$date4);

image

You have a space before the & of ended_at and after the = of ended_at=

Additionally your dates are back to front

start_at=now&end_at=sevendays_ago

So no results