Mammouth du PHP |
725 Messages
26 avr. 2013, 03:08
voici le code complet:
<?php
include 'facebookLib.php';
include 'config.php';
// get application appID and appSecret
$config = array(
'appId' => $AppID,
'secret' => $AppSec,
);
// initiate facebook config
$facebook = new Facebook($config);
$sqlPost = 'SELECT * FROM fb_posts WHERE action = "0" ORDER BY p_id ASC LIMIT 1';
//echo $sqlPost;
$reqPost = $connexion->query($sqlPost);
$resultPost = $reqPost->fetchAll();
$total_comPost = count($resultPost);
// check if anything to post
if($total_comPost)
{
foreach($resultPost as $kPost=>$vPost)
{
$p_id = $vPost['p_id'];
$p_type = $vPost['p_type'];
$p_message = $vPost['p_message'];
$p_title = $vPost['p_title'];
$p_description = $vPost['p_description'];
$p_caption = $vPost['p_caption'];
$p_picture = $vPost['p_picture'];
$p_link = $vPost['p_link'];
} // end foreach($resultPost as $kPost=>$vPost)
// select all users to post to
$select_Afb = 'SELECT user_id, account_type, access_token FROM fb_users';
//echo $select_Afb.'<br />';
$req_Afb = $connexion->query($select_Afb);
$result_Afb = $req_Afb->fetchAll();
$total_Afb = count($result_Afb);
//echo $total_Afb.'<br />';
foreach($result_Afb as $Akey=>$Aval)
{
$user_id = $Aval['user_id'];
$account_type = $Aval['account_type'];
$access_token = $Aval['access_token'];
// if it is a page
if($account_type == 2) // we need to add access_token
{
$attachments = array(
'access_token' => $access_token,
'type' => $p_type,
'message' => $p_message,
'name' => $p_title,
'description' => $p_description,
'caption' => $p_caption,
'picture' => $p_picture,
'link' => $p_link,
);
}
else
{ // normal user
$attachments = array(
'type' => $p_type,
'message' => $p_message,
'name' => $p_title,
'description' => $p_description,
'caption' => $p_caption,
'picture' => $p_picture,
'link' => $p_link,
);
} // end if($account_type == 2)
$ret_obj = $facebook->api('/'.$user_id.'/feed', 'post', $attachments);
$facebook->api('/'.$user_id.'/feed', 'post', $attachments);
} // end foreach($result_Afb as $key=>$val)
} // end if($total_comPost)
?>