TheHabbos API Help

Coder

Member
Jan 4, 2011
34
0
Basically, I have customized the API (Beta 2) to my liking, but for some reason the queries are not working.

Suggestion: Make a way for us to test the API (eg a test account we can vote for a million times a day, or a URL we can link it to (sandbox.thehabbos.org) where instead of a vote, it will let us pick which message we would like to receive (1 = Successfuly Voted, 2 = Voted Already, 3 = Hasnt voted, 4/5 = Invalid Request, 6 = Connection Error) as it is detailed in the API.

However, mine is failing.

PHP:
case 1:
  {
    //what happens if someone does successfully vote
    $get_hp = mysql_query("SELECT * FROM users WHERE id = '".$my_id."'") or die(mysql_error());
    $hp = mysql_fetch_assoc($get_hp);
    $creds = $hp['credits'];
    $hp = $hp['honor_awarded'];
    
    $new_hp = $hp + $CONFIG['Honor'];
    $new_creds = $creds + $CONFIG['Credits'];
    mysql_query("UPDATE users SET `honor_awarded` = '".$new_hp."', `credits` = '".$new_creds."' WHERE `id` = '".$my_id."'");
    @SendMusData('UPRC' . $my_id);
    
    header('Location: me.php?vote=1');
    break;
  }

NOTE: I have included core.php and mus.php in the includes.php file.
Also NOTE: The Redirect header (me.php?vote=1) is working perfectly.

In testing this (for PHP errors) I placed it in me.php if a $_GET['vote'] variable exists. It worked everytime. So idk what the problem is.
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,932
Have you included global.php, or whatever file that your CMS includes for handling MySQL? If not, you should include that in the includes.php file.
 

Coder

Member
Jan 4, 2011
34
0
I just did a test, it turns out the variable $my_id wasn't even being passed to this file (via the core which I included in includes.php)... I included core.php on this page instead, and it passed the variable... still doing some more testing. Trying to find people who haven't voted to test for me :S
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,932
I just did a test, it turns out the variable $my_id wasn't even being passed to this file (via the core which I included in includes.php)... I included core.php on this page instead, and it passed the variable... still doing some more testing. Trying to find people who haven't voted to test for me :S

I've created a quick script to allow you to check if your script is working for a certain case.

Go into "class.validate.php", and replace the file with the following code:
PHP:
<?php
//////////////////////////////////////////////////////////////
// # TheHabbos Topsites API Script - Release 1.0.0 (BETA 2) //
// # (C) Copyright TheHabbos 2010. All rights reserved.     //
//////////////////////////////////////////////////////////////

if(!defined('IN_THEHABBOS_API')) {
  die('Sorry, but you can not access this file directly. :(');
}

class Validate {
  function validateVote() {
    global $CONFIG;
    if(!isset($_GET['api_code']) {
      $handle = @fopen('http://api.thehabbos.org/validate.php?user='.$CONFIG['Username'].'&ip='.$_SERVER['REMOTE_ADDR'], 'r');
    }else{
      $handle = @fopen('http://api.thehabbos.org/sandbox.php?return='.$_GET['api_code'], 'r');
    }
    if(!$handle) {
      return 6;
    }else{
      $validateCode = stream_get_contents($handle); fclose($handle);
      return $validateCode;
    }
  }
}

So you can change the case to what you want based on the value you set api_code to:

Just remember to change the file back to the default code when you make this script go live, or it could be obviously abused.
 

Coder

Member
Jan 4, 2011
34
0
I See you took my suggestion :D Thanks

Also, you are missing a parentheses there at line 14
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,932
oic

PHP:
<?php
//////////////////////////////////////////////////////////////
// # TheHabbos Topsites API Script - Release 1.0.0 (BETA 2) //
// # (C) Copyright TheHabbos 2010. All rights reserved.     //
//////////////////////////////////////////////////////////////

if(!defined('IN_THEHABBOS_API')) {
  die('Sorry, but you can not access this file directly. :(');
}

class Validate {
  function validateVote() {
    global $CONFIG;
    if(!isset($_GET['api_code'])) {
      $handle = @fopen('http://api.thehabbos.org/validate.php?user='.$CONFIG['Username'].'&ip='.$_SERVER['REMOTE_ADDR'], 'r');
    }else{
      $handle = @fopen('http://api.thehabbos.org/sandbox.php?return='.$_GET['api_code'], 'r');
    }
    if(!$handle) {
      return 6;
    }else{
      $validateCode = stream_get_contents($handle); fclose($handle);
      return $validateCode;
    }
  }
}
 

Coder

Member
Jan 4, 2011
34
0
Alright, so I'm having some major problems in getting this to work.

Could you explain exactly how this works? [i.e. what happens, step by step?]

It would help in learning to use it properly.. most of my users are saying they were asked to log in after voting (so I assume their sessions expired). But some are correctly being redirected to me.php?vote=1 (as I set up in other.php) but not receiving their points or credits. It worked when I did it with sandbox... but not with the actual one :/

I am also assuming that you include or redirect to the api.php link we provided to your site (via the hidden input), AFTER they vote. Is there anyway you can make it so it goes there first, or we can provide you with a URL to check if the session is set?

Sorry to be a pain, but I really want this to work. You're the first topsites to incorporate or develop an API. So thanks for that, but I wish it was easier to work with :/
 

Users who are viewing this thread

Top