jedi-gg / swgoh.gg.public

SWGOH.GG Issues
https://swgoh.gg
41 stars 12 forks source link

API calls from PHP returning 403 Forbidden #750

Closed driderdesigns closed 2 years ago

driderdesigns commented 2 years ago

PHP calls to the player API are now returning http 403. The same URL is returning just fine in the browser. First noticed around 20 Apr, was working fine before this. Possibly related to #709

PHP Code that used to work used is included below, along with the URL I'm using (my Player ID). I tried a few different methods, all returned 403.

function getTestData()
{
    // FAILS
    $url = "https://swgoh.gg/api/player/838822353/";

    // WORKS
    //$url = "https://chart.googleapis.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World&chof=json";

    $json = file_get_contents($url);

    // Some online comments indicate possible missing UserAgent being the cause

    /*  Tried setting User Agent in ini
        ini_set( 'user_agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' );
        $json = file_get_contents($url);
    */

    /* Tried setting UA in context
        $opts = array(
            'http'=>array(
                'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
                'method'=>"GET",
                'header'=> implode("\r\n", array('Content-type: text/plain;'))
            )
        );
        $context = stream_context_create($opts);
        $json = file_get_contents($url, false, $context);
    */

    // Also tried fopen
    // $json=fopen($url,"rb");

    echo $json;
}
scobenes commented 2 years ago

We implemented some anti bot into our CDN. Contact Sep#1111 on discord and he will see what we can do for your use case. Just a warning that he is on vacation and prob wont get back to you til next week.

lc9900 commented 2 years ago

Can you provide the link to the discord server for swgoh.gg? For some reason, I can't find it. Thank you. @scobenes

scobenes commented 2 years ago

yup np, its on the bottom of the website, but here is direct link https://discord.gg/ZgZyqtGZm4

lc9900 commented 2 years ago

Awesome. Thank you very much

driderdesigns commented 2 years ago

The site I'm using the API with is https://swgoh.driderdesigns.com. Just a small tracker to help show me what I'm missing, a GL farming summary, and a meta teams list. I think the github repo is public, but if not and you need to see it, just let me know.

https://swgoh.driderdesigns.com/roster/838822353 is my current page, hard-coded at the moment.

lc9900 commented 2 years ago

I got on the discord, and found the announcement. They just changed the api url. Instead swgoh.gg/api/, it's now api.swogh.gg. Don't need that /api neither.