1. I have corrected the e-mail settings so that outgoing e-mails from these forums should be sent now. If you tried to Register or Reset your Password, please try again!
    Dismiss Notice

updates on API info

Discussion in 'Census: General Discussion' started by FrenchBread, Apr 3, 2013.

  1. FrenchBread

    FrenchBread Guest

    is there a spot where the developers are posting information regarding the API ? I just checked and the Leaderboards for PS2 have service unavailable :( some kind of info would be fantastic!
     
  2. Evilfish

    Evilfish Guest

    Service Unavailable happens from time to time, and you have to deal with that in your logic. My own PS2 page does this by retry the call that failed with Service unavailable, but only after a 30 second wait period. I do this to make sure the API has time and breathing room. I guess the API sometimes gets a bit overloaded, and that's why this happens. My page usually only does one retry and can then continue on. Here is my C# code for my api caller:

    Code:
    /// <summary>
            /// Downloads a string from a url. This method will try to do it as many times aslong it only gets
            /// a HttpStatusCode.ServiceUnavailable response code as an error. All other errors will be thrown as
            /// a WebExpection.
            /// <para>If it fails after a given number of retries, an exception is thrown.</para>
            /// <para>If retries are set to -1, it will continue nonstop.</para>
            /// </summary>
            /// <param name="url">Url to download</param>
            /// <param name="retries">Number of retries, -1 for nonstop</param>
            /// <returns>result</returns>
            public static String downloadStringFromUrl(String url, int retries, APIImporter importer)
            {
                int i = 0;
                bool ignoreTries = (retries == -1);
                while (i < retries || ignoreTries)
                {
                    try
                    {
                        String response = importer.webClient.DownloadString(url);
                        return response;
                    }
                    catch (WebException e)
                    {
                        //If service is unavailable, try again in 30 seconds
                        HttpWebResponse response = (HttpWebResponse)e.Response;
                        if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
                        {
                            importer.reportProgress("Could not download at this time. Retrying in 30 seconds", 'w');
                            Thread.Sleep(30000);
                        }
                        else
                        {
                            importer.reportProgress("Unexpected WebException code " + response.StatusCode + " while downloading", 'e');
                            throw;
                        }
                    }
                    i++;
                }
                throw new Exception("No response within " + i + " retries. ");
            }
    Hope it helps.
     
    Last edited by a moderator: Dec 14, 2016
  3. FrenchBread

    FrenchBread Guest

    I solved the issue by doing something similar :p
    $output = API data link
    if(!$output){
    error message
    } else {
    do work!
    }

    :)
     

Share This Page