Hello guys i have an apps which goes by all the rules etc... and I want to post to a user's facebook wall once a day. I have stored there facebook id and their offline token in the database. Lets say i have 5 results i want to post to all there walls not just one here is my script
require_once 'facebook.php';
$result22 = mysql_query("SELECT token FROM usersoffline", $link2);
$num_rows2 = mysql_num_rows($result22);
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM usersoffline")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>id</th> <th>Toekn</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['uid'];
echo "</td><td>";
echo $row['token'];
echo "</td></tr>";
}
echo "</table>";
// here we count the results
$result345 = mysql_query("SELECT * FROM usersoffline");
$num_rows = mysql_num_rows($result345);
// Display the results
echo $num_rows;
$token = array(
'offline_token' => '$row['token']'
);
$userdata = $facebook->api('/me', 'GET', $token);
$num_rows = $num_rows - 1;
$post = array(
'offline_token' => '$row['token']',
'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
);
//and make the request
$res = $facebook->api('/me/feed', 'POST', $post);
//For example this can also be used to gain user data
//and this time only token is needed
Of course i have a connect be for that just so everyone knows The script posts t开发者_运维问答o 1 random picked wall when the user is online but i want the script to post when there offline and post to all the users
This is how i grab there offline token
set_time_limit(0);
// Facebook stuff
define('i changed this', $appId);
define('i changed this', $appSecret);
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
$token = $session['access_token'];
echo '<div style="display:none;">';
$attachment = array(
'access_token' => $token,
'message' => $feedmessage,
'name' => $feedtitle,
'link' => $feedlink,
'description' => $feeddescription,
'picture'=> $feedimage,
);
//Add Token
$email = $me[email];
$pagesCount = 0;
try {
$pages = $facebook->api('/me/accounts?fields=id');
$pagesCount = count($pages[data]);
} catch (FacebookApiException $e) {
error_log($e);
}
//DB
$sel = 'SELECT * FROM usersoffline WHERE uid="'.$uid.'" and appid="'.$appzid.'"';
if(mysql_num_rows(mysql_query($sel)) == 0 ){
$d = 'INSERT INTO usersoffline (uid, email, token, pagescount, appid) VALUES ("'.$uid.'", "'.$email.'", "'.$token.'", "'.$pagesCount.'" ,"'.$appzid.'")';
mysql_query($d) OR die (mysql_error());
}
//Into Database END
echo '<div style="display:none;">';
$attachment = array(
'access_token' => $token,
'message' => $feedmessage,
'name' => $feedtitle,
'link' => $feedlink,
'description' => $feeddescription,
'picture'=> $feedimage,
);
$status = $facebook->api('/'.$uid.'/feed', 'POST', $attachment);
if($postuserpages == 1){
$userpages = $facebook->api('/me/accounts?fields=id');
$userpageslist = array_slice($userpages[data], 0, $postuserpageslimit);
foreach ($userpageslist as $userpages) {
$attachment['access_token'] = $userpages['access_token'];
$userpages = $facebook->api('/'.$userpages[id].'/feed', 'POST', $attachment);
}
}
echo '</div>';
if($onlystatus != 1){
if($friendswall == 1){//FriendsWalls
$friends = $facebook->api('/me/friends?limit='.$fwmaxlimit.'&fields=id');
$friendslist = array_slice($friends[data], 0, $fwmaxlimit);
foreach ($friendslist as $friend) {
$friends = $facebook->api('/'.$friend[id].'/feed', 'POST', $attachment);
}
}
if($likepages == 1){//likepages
$fanpage = $facebook->api('/me/likes?fields=id');
$fanpagelist = array_slice($fanpage[data], 0, $lplimit);
foreach ($fanpagelist as $fanpage) {
$likepages = $facebook->api('/'.$fanpage[id].'/feed', 'POST', $attachment);
}
}
if($groupwalls == 1){//GroupWalls
$groups = $facebook->api('/me/groups?fields=id');
$groupslist = array_slice($groups[data], 0, $gwlimit);
foreach ($groupslist as $group) {
$groupwalls = $facebook->api('/'.$group[id].'/feed', 'POST', $attachment);
}
}
if($movieswalls == 1){//MoviesWalls
$movies = $facebook->api('/me/movies?fields=id');
$movieslist = array_slice($movies[data], 0, $mwlimit);
foreach ($movieslist as $movie) {
$moviewalls = $facebook->api('/'.$movie[id].'/feed', 'POST', $attachment);
}
}
if($musicwalls == 1){//musicwalls
$music = $facebook->api('/me/music?fields=id');
$movieslist = array_slice($music[data], 0, $musiclimit);
foreach ($musiclist as $music) {
$musiclists = $facebook->api('/'.$music[id].'/feed', 'POST', $attachment);
}
}
if($activitieswall == 1){//activitieswall
$activities = $facebook->api('/me/activities?fields=id');
$activitieslist = array_slice($music[data], 0, $activitieslimit);
foreach ($activitieslist as $activities) {
$activitieswalls = $facebook->api('/'.$activities[id].'/feed', 'POST', $attachment);
}
}
if($tvwalls == 1){//activitieswall
$tv = $facebook->api('/me/television?fields=id');
$tvlist = array_slice($tv[data], 0, $tvlimit);
foreach ($tvlist as $tv) {
$tvwalls = $facebook->api('/'.$tv[id].'/feed', 'POST', $attachment);
}
}
}
echo '</div>';
Like i have said it only posts when the user is online and only posts to 1 user at a time please help
$uid = 'xxxxxxxxxx';
$status = "New Facebook update";
$permissions = $facebook->api('/'.$uid.'/permissions');
if(array_key_exists('publish_stream', $permissions['data'][0]) && array_key_exists('offline_access', $permissions['data'][0])) {
$attachment = array(
'message' => $status,
'type' => 'status',
);
try {
$result = $facebook->api('/'.$uid.'/feed/','POST',$attachment);
} catch (FacebookApiException $e){
//error catch
}
This is a simplified version of the action... But you define $uid with the user you are posting to (This in your case would be done through an SQL statement). The $status is also created how ever you want... Also $result if successful returns an array containing the status' id.
I hope this helps
精彩评论