0

I am using whatsapi from github and the examples/whatsapp.php. I have configured my number, password etc properly...

however, when i execute the program, after logging in, when i try to select user which is supposed to get my contacts and groups, JS error 'Error: There was an error with the AJAX request. XML/Json format is bad.' comes up.

On checking firbug console, i got the following php error message;


Notice: Undefined index: id in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\Landshoppe \WAPP\Chat-API-master\examples\whatsapp.php on line 321
{"success":true,"type":"contacts","data":....

The function which calls it is

public function __construct(array $config)
{
    $this->config = $config;

    if ($_SERVER['REQUEST_METHOD'] == "POST") {
        try {
            $this->inputs = $this->cleanPostInputs();

            if (isset($this->inputs['from'])) {
                $this->from = $this->inputs['from'];

                if (!array_key_exists($this->from, $this->config)) {
                    exit(json_encode(array(
                        "success" => false,
                        'type' => 'contacts',
                        "errormsg" => "No config settings for user  $this->from could be found"
                    )));
                } else {
                    $this->number = $this->config[$this->from]['fromNumber'];
//  --This is the Line--   $this->id = $this->config[$this->from]['id'];
                    $this->nick = $this->config[$this->from]['nick'];
                    $this->password = $this->config[$this->from]['waPassword'];

                    $this->wa = new WhatsProt($this->number, $this->nick, false);
                    $this->wa->eventManager()->bind('onGetMessage', array($this, 'processReceivedMessage'));
                    $this->wa->eventManager()->bind('onConnect', array($this, 'connected'));
                    $this->wa->eventManager()->bind('onGetGroups', array($this, 'processGroupArray'));
                }
            }
        } catch (Exception $e) {
            exit(json_encode(array(
                "success" => false,
                'type' => 'contacts',
                "errormsg" => $e->getMessage()
            )));
        }
    }
}

after that all groups and contacts are defined therein ! but program is paused with the JSON error !

So what should i do to rectify the 'undefined index id' ?

user3526204
  • 509
  • 5
  • 22

1 Answers1

1

I finally found out that it was the 'require_once "src/whatsprot.class.php"' that was holding up the script. When I changed to 'require' or 'include', it works fine. The reason I believe is, the json call after the file is loaded requires the 'whatsprot.class.php' file again but could not find it as it is loaded only once using 'require_once' !

user3526204
  • 509
  • 5
  • 22