I have a cron file
that runs to post images to Instagram, once the image get posted, the code updates the MySQL table as successful. some times, if the logging to Instagram was not successful (or) IP blocked then a server response shows ("status":"fail")
. how to use (if) to read the http response then update MySQL as fail?
PHP Version: 5.6.35
Server http response:
{"message": "checkpoint_required", "checkpoint_url": "https://i.instagram.com/challenge/8633340132/qz34BIU1MQ/", "lock": true, "status": "fail", "error_type": "checkpoint_challenge_required"}
Current posting code:
<?php
require_once("helper/functions.php");
require_once("cron_insta_include.php");
$result_outmsg = $database->query("SELECT * FROM insta_sent");
while($row_outmsg = $database->fetch_array($result_outmsg))
{
if($row_outmsg["report"] == "Scheduled")
{
$res_ch = $database->query("SELECT * FROM insta_ch WHERE serial='" . $row_outmsg["fromch"] . "'");
$row_ch = $database->fetch_array($res_ch);
if(($row_ch["status"] != "Blocked") && ($row_ch != false))
{
if((time() - $row_ch["last_used"]) > 7200)
{
try
{
//Insta Sending
$cap = "." . "
" . $row_outmsg["body"] . "
" . "." . "
" . $row_outmsg["hash"] . "
" . "." . "
" . $row_outmsg["tonum"] . "
" . "." . "
" . time();
$obj = new InstagramUpload();
$obj->Login($row_ch["phone"], $row_ch["ch_id"]);
$obj->UploadPhoto($row_outmsg["img_lnk"], $cap);
sleep(1);
$database->query("UPDATE insta_sent SET report='Sent' WHERE serial='" . $row_outmsg["serial"] . "'");
}
catch(Exception $e)
{
$database->query("UPDATE insta_sent SET report='Failed' WHERE serial='" . $row_outmsg["serial"] . "'");
}
$sql_13 = "UPDATE insta_ch SET last_used='" . time() . "' WHERE serial='" . $row_outmsg["fromch"] . "'";
$database->query($sql_13);
}
}
else
{
//$database->query("UPDATE insta_sent SET report='Not Sent' WHERE serial='" . $row_outmsg["serial"] . "'");
}
}
}
?>