简体   繁体   中英

PHP: How to capture data from Livehealth Webhook API

You need to place this code first in your end file (which you shared with the live health API team.) They will enable access to this file and once any report will submit, data will be sent on endfile. you need to place this below code in that file and you will get a file created in the same root and will see data received from live health API.

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // fetch RAW input
    $json = file_get_contents('php://input');

    // decode json
    $object = json_decode($json,true);

    // expecting valid json
    if (json_last_error() !== JSON_ERROR_NONE) {
        die(header('HTTP/1.0 415 Unsupported Media Type'));
    }
     
    $time = time();
    $fname ='_callback.test.txt'; 
    file_put_contents($time.$fname , print_r($object, true));

    $jdonFile = time().'_json_callback.test.txt';
    $filename = $jdonFile;
    $handle = fopen($filename, "w");
    fwrite($handle, $json);
    fclose($handle);

}

Using this code i was able to get data and i store this data into txt file. you can insert this data in sql database. just copy and past the same code and your script will execute.

 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        // fetch RAW input
        $json = file_get_contents('php://input');
    
        // decode json
        $object = json_decode($json,true);
    
        // expecting valid json
        if (json_last_error() !== JSON_ERROR_NONE) {
            die(header('HTTP/1.0 415 Unsupported Media Type'));
        }
         
        $time = time();
        $fname ='_callback.test.txt'; 
        file_put_contents($time.$fname , print_r($object, true));
    
        $jdonFile = time().'_json_callback.test.txt';
        $filename = $jdonFile;
        $handle = fopen($filename, "w");
        fwrite($handle, $json);
        fclose($handle);
    
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM