Hi there!

I have a PHP code that post on timeline everthing is working perfectly fine only it show text two times i have attached the code and the image please tell me where is the issue.

<?php
$re4=mysql_query(" SELECT FBID FROM users WHERE U_ID='$U_ID' ");
while ($ro4=mysql_fetch_assoc($re4)){
                                     extract($ro4);
                                    }

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://graph.facebook.com/$FBID/accounts/?access_token=$AccessToken");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);
$pageIds = json_decode($result, true);

$c=0;
$pageAccessToken="";
$c=0;
while ($c<count($pageIds['data'])){
                                   if ($Fanpage==$pageIds['data'][$c]['id']){$Key=$c; $PageName=$pageIds['data'][$c]['name'];}
                                   $c=$c+1;
                                 }
//Get the access token
$pageAccessToken=$pageIds['data'][$Key]['access_token']; 

if ($PostGraphic!="" && $pageAccessToken!="" && $LinkURL==""){

//posting a graphic to a fan page, post to the photo album to show large graphic

try {    

    $msg_body = array(
                      'access_token' => $pageAccessToken,   
                      'message'      => $PostText,
                      'source'       => '@' . realpath('../members/PostImages/'.$PostGraphic)                  
                     );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://graph.facebook.com/$Fanpage/photos/");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $msg_body);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
    $result = curl_exec($ch);
    curl_close ($ch);
    $js = json_decode($result);
    //print_r($js);
    //exit();
    $ID = $js->post_id;    

    $re=mysql_query(" UPDATE posts SET PostID='$ID' WHERE P_ID='$P_ID' ");
    $re=mysql_query(" UPDATE posts SET IsPost='1' WHERE P_ID='$P_ID' ");
} catch (Exception $e) {       
    $err_str = $e->getMessage();
}
}else{
      //posting either text only or to a group, post to feed, small picture if one is attached also do this post if it is a link

      //if there is a page access token then post as the page and not as the user
      if ($pageAccessToken!=""){$AccessToken=$pageAccessToken;}

       $msg_body = array('access_token' => $AccessToken,   
                  'name' => '',
                  'message' => $PostText,
                  'caption' => $Caption,
                  'link' => $LinkURL,
                  'description' => '', 
                  'picture' => 'http://www.postpromotions.com/members/PostImages/'.$PostGraphic,
                  'url' => 'http://www.postpromotions.com/members/PostImages/'.$PostGraphic,
                  'source' => 'http://www.postpromotions.com/members/PostImages/'.$PostGraphic
                  );

try {
    //this is the API call that does it all
    //$result = $facebook->api($Fanpage.'/feed/', 'post', $msg_body);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://graph.facebook.com/$Fanpage/feed");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $msg_body);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
    $result = curl_exec($ch);
    curl_close ($ch);
    $js = json_decode($result);
    //print_r($result);
    $ID = $js->id;    

    $re=mysql_query(" UPDATE posts SET PostID='$ID' WHERE P_ID='$P_ID' ");
    $re=mysql_query(" UPDATE posts SET IsPost='1' WHERE P_ID='$P_ID' ");
   } catch (Exception $e) {       
                           $err_str = $e->getMessage();
                           //echo $err_str;
                          }
}
?>

34eafa021b7dc32864c9b1c61075ef6f

Member Avatar for LastMitch

I have a PHP code that post on timeline everthing is working perfectly fine only it show text two times i have attached the code and the image please tell me where is the issue.

@Rizi004

There's nothing wrong with the PHP code.

I think it's more related to JSON/javascript part.

Which you didn't provided it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.