Warning: file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

Avatar image for lashaparesha
lashaparesha

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#1  Edited By lashaparesha

Hello im getting this error when i want to get content from api

Warning: file_get_contents(http://www.giantbomb.com/api/platforms/?api_key=4c9947799502fd3688ae8*******&sort=release_date:desc&field_list=id,image,name,date_added,deck,platforms&limit=10&offset=0&format=json): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in/home/u******/public_html/api/games/all_platforms.php on line 10

Avatar image for flippyandnod
flippyandnod

758

Forum Posts

2

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Is that a valid URL? I think there is supposed to be some text between the / and the ?. Actually I think the / before the ? shouldn't be there at all. Try taking that one out and having the ? follow the s in platforms directly.

You're a bit crazy to send your API key over http, btw. You should be using https.

Avatar image for jslack
jslack

1186

Forum Posts

1165

Wiki Points

0

Followers

Reviews: 1

User Lists: 6

#3  Edited By jslack

@lashaparesha: The endpoint request works perfectly. The issue is how you're making the call.

To me, it looks like you are making this call on your own webserver, in php using file_get_contents? You can't do file_get_contents on this remote address. Use curl instead.

Avatar image for lashaparesha
lashaparesha

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

@flippyandnod: when i enter this url on browser adress bar its give me content, but from site its not working
https://www.giantbomb.com/api/platforms/?api_key=4c9947799502fd3688ae86********************&sort=release_date:desc&field_list=id,image,name,date_added,deck,platforms&limit=10&offset=0&format=json

Avatar image for lashaparesha
lashaparesha

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#5  Edited By lashaparesha

@jslack: how to make with curl can u give me example?

there is my example :

$vdata = file_get_contents('https://www.giantbomb.com/api/platforms/?api_key='.$giantbomb_key.'&sort=release_date:desc&field_list=id,image,name,date_added,deck,platforms&limit=10&offset='.$offset.'0&format=json');

$vresponse = json_decode($vdata);

Avatar image for szlifier
szlifier

1518

Forum Posts

120

Wiki Points

0

Followers

Reviews: 0

User Lists: 4

#6  Edited By szlifier

@lashaparesha: You have to specify a User-Agent, e.g. "lashaparesha api script".

You can do that in file_get_contents and curl.

I used to have this on QLCrew:

$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: lashaparesha api script\r\n"
));

$context = stream_context_create($opts);

$url = http://www.giantbomb.com/api/..........

$file = file_get_contents($url, false, $context);

Avatar image for lashaparesha
lashaparesha

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#8  Edited By lashaparesha

@szlifier:

sorry mate im new on codding and im getting this error >> Parse error: syntax error, unexpected ':' in /home/u155508610/public_html/api/games/all_platforms.phpon line 19

here is code

$opts = array(

'http'=>array(

'method'=>"GET",

'header'=>"User-Agent: lashaparesha api script\r\n"

));

$context = stream_context_create($opts);

$url = https://giantbomb.com/api/platforms/?api_key='.$giantbomb_key.'&sort=release_date:desc&field_list=id,image,name,date_added,deck,platforms&limit=10&offset='.$offset.'0&format=json

$file = file_get_contents($url, false, $context);

$vresponse = json_decode($vdata);

if ($vresponse->results==NULL){

echo '';

}else{

foreach ($vresponse->results as $vresult)

Avatar image for jslack
jslack

1186

Forum Posts

1165

Wiki Points

0

Followers

Reviews: 1

User Lists: 6

@lashaparesha: You need to put quotes around your url. (among other problems).

$url = 'https://giantbomb.com/api/platforms/?api_key='.$giantbomb_key.'&sort=release_date:desc&field_list=id,image,name,date_added,deck,platforms&limit=10&offset='.$offset

Avatar image for lashaparesha
lashaparesha

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#10  Edited By lashaparesha

fixed dear friends thanks so much!!! :*