pimax / fb-messenger-php

Facebook Messenger Bot PHP API
GNU General Public License v2.0
314 stars 147 forks source link

php://input always empty #6

Closed h2u closed 8 years ago

h2u commented 8 years ago

Not sure that it's your package problem but i have nothing in $data variable (json_decode(file_get_contents("php://input"), true)). Can't find any soultion about this.

Im writing data to file like (file_putcontents('bot'.time().'.txt', print_r($data, true));) this and file is empty.

Can you please help me?

ya-kostik commented 8 years ago

Try to log file_get_contents("php://input") without json_decode

Can you get some samples of your code with this problem?

P. S. GET or DELETE methods doesn't have body, and php://input will be empty

h2u commented 8 years ago
<?php
if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] == 'subscribe' && $_REQUEST['hub_verify_token'] == "<mytoken>") {
    echo $_REQUEST['hub_challenge'];
} else {
    $data = json_decode(file_get_contents("php://input"), true);
    file_put_contents('bot_'.time().'.txt', print_r($data, true));
}
?>

The first part of code needs only to verify webhook. I think Facebook sends PUT method to webhook. I can't access ftp now, so I will try to write "php://input" to file later today and give you answer, @ya-kostik.

maxpinyugin commented 8 years ago

Please, check web server logs. php://input not getting through if request has an redirection. Maybe your webserver has an redirect from www. to url without www or maybe without slash on wnd of address to without slash.

h2u commented 8 years ago

Thank you guys. @ipimax you were right. I had url like https://domain.com/bot, and it has redirect to /bot/ (added slash).

So I changed url and it's ok now.

manix commented 6 years ago

Just ran into a similar issue, worth mentioning that the app won't get any data if it's not public, not even for admins.

image

o2-web commented 6 years ago

@manix You need to pass app review include business verification (if needed)

this is a separate topic for discussion)