Объект JSON из чат-бота мессенджера в переполнении стека

Я использую чат-мессенджер со скриптом ниже из Учебник мистера Надима Мансура

Когда я получаю объект JSON в строке 15:
$input = json_decode(file_get_contents('php://input'), true);
Я хочу сохранить весь объект в виде текста в файле .txt. Как это можно сделать? Я буду признателен за любую помощь.
Есть целый сценарий:

    <?php

/* validate verify token needed for setting up web hook */
if (isset($_GET['hub_verify_token'])) {
if ($_GET['hub_verify_token'] === 'codeandpepper') {
echo $_GET['hub_challenge'];
return;
} else {
echo 'Invalid Verify Token';
return;
}
}

/* receive and send messages */
$input = json_decode(file_get_contents('php://input'), true);
if (isset($input['entry'][0]['messaging'][0]['sender']['id'])) {

$sender = $input['entry'][0]['messaging'][0]['sender']['id']; //sender facebook id
$message = $input['entry'][0]['messaging'][0]['message']['text']; //text that user sent

$url = 'https://graph.facebook.com/v2.6/me/messages?access_token=EAAQyP47lxSQBAPQSXyHhQ7y0d0MTQgTn4xaFEDEu5yrc4qo4t0FWbHZAfT7TFQq3HYZCUGVcTPZAaN2ZBNrUShl4Hr5qQd8cqBu0mfB0Al7NZAWjIjQC9UqXQLU5E9IsZBaQDIXglMcEBqNUyiidGJWRPPfvCmtg4vy2UgUhU8SQZDZD';

/*initialize curl*/
$ch = curl_init($url);
/*prepare response*/
$jsonData = '{
"recipient":{
"id":"' . $sender . '"},
"message":{
"text":"You said, ' . $message . '"}
}';
/* curl setting to send a json post data */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if (!empty($message)) {
$result = curl_exec($ch); // user will get the message
}
}

?>

-1

Решение

Если вы хотите сохранить строку JSON, и это будет самым простым и чистым способом, вам придется разбить эту строку и затем просто file_put_contents() строка с именем файла

/* receive and send messages */
$input = json_decode(file_get_contents('php://input'), true);

В

/* receive and send messages */
$json_str = file_get_contents('php://input');
file_put_contents('path/to/file.txt', $json_str);
$input = json_decode($json_str, true);

// and off you go as normal
1

Другие решения

Других решений пока нет …