Mojang API is kinda poo to me [PHP]

Discussion in 'Programming' started by Spooky18, Jun 19, 2015.

  1. Hi, I have the following PHP code that will change the Players Username to the correct casing using the mojang api, Although its failing on me today, I haven't touched it since it was working.
    PHP:
    $arr  = array(
        "name" => $user,
        "agent" => "minecraft"
    );
    $data = json_encode($arr);

    $ch = curl_init('https://api.mojang.com/profiles/page/1');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data)
    ));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    if (!($res = curl_exec($ch))) {
        echo ('[cURL Failure] ' . curl_error($ch));
    }

    curl_close($ch);
    $username = json_decode($res, true);
    $mc       = $username['profiles']['0']['name'];
    Just returns [cURL Failure]
     
  2. @nfell2009
    Heard he likes PHP, maybe he can help ;)
     
  3. Don't bump thread which aren't at least 24h old.
     
    • Funny Funny x 1
  4. Tux

    Tux

  5. All you want to do is have the correct casing? Where are you getting the input from? You can use my api if you like. It's very easy to use and extends Mojang Api. Link in my sig
     
  6. Erm, maybe try something like this:
    Code (Text):

    $res = curl_exec($ch);
    if(curl_errno($ch)){
         echo curl_error($ch);
         return false;
    }
    curl_close($ch);