pimax/fb-messenger-php

Method call() not working with http_build_query($data) for CURLOPT_POSTFIELDS

Closed this issue · 9 comments

FbBotApp.php in method call() in this part of the code, I had to change http_build_query to json_encode, because if you use http_build_query then when sending a message Facebook returns an error:

Array
(
    [error] => Array
        (
            [message] => An active access token must be used to query information about the current user.
            [type] => OAuthException
            [code] => 2500
            [fbtrace_id] => D5nVvpItwir
        )

)

but working good if:

if ($type == self::TYPE_POST || $type == self::TYPE_DELETE) {
    curl_setopt($process, CURLOPT_POST, 1);
    // curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($process, CURLOPT_POSTFIELDS, json_encode($data));
}

is that just me?

@jason-engage

[2018-06-22 23:27:53] local.INFO: $data = Array
(
    [recipient] => Array
        (
            [id] => 1614553048605991
        )

    [message] => Array
        (
            [text] => test111
        )

    [tag] => 
    [notification_type] => REGULAR
    [messaging_type] => RESPONSE
    [access_token] => EAAb8AuRIi2wBAJnjfIXUPEGixBmZBIkjLXFiICUXG5EkJK4XcF7ZAjqhiCTnsPZAXIrgmBzhgL05OdXlfD0nseZAssZBQRIpI3SB01oG8dv6WALDwAkZCHXqss7ilBmIQIjfQVk0ZCEA36PJHasZBpWxmZBRXNV6U8ZB1V3DF0HkxrnyqcK6xnrQdn
)

@jason-engage does it work fine for you with http_build_query now?

a couple of days ago I was working fine with http_build_query, but today I had to change to json_encode

@jason-engage this problem I noticed yesterday, but only today found a way to get rid of it

Yes, you're right, the json_encode is necessary

I think the issue can be closed. Saw the last commit. Thank you!