Avatar image for deactivated-5b17b9d9a59ea
#1 Posted by deactivated-5b17b9d9a59ea (4 posts) -

Hey guys and @jslack,

I'm having some troubles using your API.
I've signed up for an API key, tested an API call in my browser and got a successful response.
Then I've implemented it into my project which is a PHP project.
But when I try to get the response via PHP it fails. It always throws a 403 error, forbidden.

So, is there a restriction I don't know of? Any IP whitelisting options or request methods that are restricted?
I'm trying to get the JSON response with "file_get_contents". I've also tried getting it with "fopen" or CURL.
You can see the error message below (Token replaced).

Warning: file_get_contents(http://www.giantbomb.com/api/game/3030-12572/?api_key=<TOKEN>&format=json&field_list=name,aliases): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home/.sites/19/site2864341/web/cms/ext/quiz/pi1/get_giantbomb_data.php on line 18

If I call the API by opening the URL in my browser, I get a wonderful response:

{"error":"OK","limit":1,"offset":0,"number_of_page_results":1,"number_of_total_results":1,"status_code":1,"results":{"aliases":"OOT\nLOZ:OOT\nZelda no Densetsu: Toki no Ocarina\n\u30bc\u30eb\u30c0\u306e\u4f1d\u8aac \u6642\u306e\u30aa\u30ab\u30ea\u30ca\nZelda 64","name":"The Legend of Zelda: Ocarina of Time"},"version":"1.0"}

Any help on that? :)
I really can't explain what's going on.

Thanks a million in advance!

Avatar image for laika
#2 Posted by Laika (148 posts) -

Are you making these requests (browser and PHP) on the same machine/IP?

Avatar image for deactivated-5b17b9d9a59ea
#3 Edited by deactivated-5b17b9d9a59ea (4 posts) -

@laika: nope. The browser copy & paste request ist done in a browser on my MacBook. The request from the PHP script is executed on my server. So they come from different IP addresses and machines.

Avatar image for laika
#4 Posted by Laika (148 posts) -

It's possible that your server's IP address is in a blocked range (due to abusive behavior). PM us with the IP and we can take a look.

Avatar image for rick
#5 Edited by rick (506 posts) -

If anyone is getting this recently you're probably coming from a commercial web host. They're all blocked now by default. Send the CIDR for your server(s) to ipbans (at) gamespot.com to get whitelisted.

Avatar image for mustardbomb
#6 Edited by MustardBomb (3 posts) -

@edgework: I'm having the same problem, except i'm issuing requests from my project (javascript) and from my browser using the same machine. everything works fine in the browser, but i'm getting a nasty 403 when requesting via javascript.

Everything was fine from the js a few days ago when i first tested the code - the problem only started today (or at least, today is when i first noticed it). Thoughts on what might be going on?

Heres an example url thats causing problems (but working fine in browser), subbing out the key of course: http://www.giantbomb.com/api/search/?api_key=<APIKEY>&query=Papers,%20Please&format=json

UPDATE: more detail on the error below. I'm not using a wordpress scraper - just issuing GET requests using the Request-promise http client (https://www.npmjs.com/package/request-promise)

<h1>Wordpress RSS Reader / Scraper Blocked</h1>

<p>

Sorry we do not allow WordPress plugins to scrape our site. They tend to be used maliciously to steal our content. We do not allow scraping of any kind.

You can load our RSS feeds using any other reader but you may not download our content.

<a href='/feeds'>Click here more information on our feeds</a>

</p>

<p>

Or you're running some other sketchy bot that we don't allow. Don't go trying to impersonate any other bot now, that WILL get you permanently banned!

</p>

<p>

Or.... maybe you're running an LG Podcast player written by a 10 year old. Either way, Please stop doing that.

</p>

Avatar image for rick
#7 Edited by rick (506 posts) -

@mustardbomb: You need to send a user agent that describes who you are. Generic UAs like curl, wget, Java, PHP etc. are now ignored as are empty UAs. We need to know whose bots are knocking at the door. Set your UA to something unique like "MustardBombsAwesomeBot" and you'll be fine.

Avatar image for mustardbomb
#8 Posted by MustardBomb (3 posts) -

@edgework: Thanks for the quick response. That did it!

Avatar image for rammone4
#9 Posted by rammone4 (18 posts) -

@edgework I'm experiencing the same issue with my site http://parallel.team just followed your instructions. Hopefully that should take care of it. Thanks for the info

Avatar image for totranquilo
#11 Edited by totranquilo (1 posts) -

@edgework : Warning: file_get_contents(http://www.giantbomb.com/api/games/?

I am having the same problem, how can I solve

-------------------------------

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

$vresponse = json_decode($vdata);

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

echo '';

Avatar image for rick
#13 Posted by rick (506 posts) -

@totranquilo: http://lmgtfy.com/?q=file_get_contents+user+agent

Avatar image for sthyb99
#14 Posted by sthyb99 (1 posts) -

@rick: how do you do¿?¿?