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' ?

8
  • please post you code, it's very hard to help without anything... Commented Nov 23, 2015 at 13:19
  • Its an entire set of codes and functions and classes i am updating the answer with the relevant function. By the way, commenting out the line makes it work...but then i don't whether it is the right thing to do ! Commented Nov 23, 2015 at 13:32
  • Could you add a github link of your required library? Commented Nov 23, 2015 at 13:37
  • And pleae rephrase your question, as it currenlty stands it is very hard to read. Commented Nov 23, 2015 at 13:37
  • Well from all the information you have provided it seems id is not in the json you have received... Can you post your JSON data? Commented Nov 23, 2015 at 13:43

1 Answer 1

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' !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.