Post to facebook user wall using offline token

Hi guys, I have applications that are distributed according to all the rules, etc .... and I want to publish them on my facebook wall once a day. I saved there facebook id and their autonomous token in the database. Suppose I have 5 results that I want to publish on all walls, not just here. 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('Ymd 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 connection for this, so that everyone knows the script puts in 1 randomly selected wall when the user is connected to the network, but I want the script to send a message when it is disconnected and sent to all users

This is how I captured an autonomous token there.

 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>'; 

As I said, these are only messages when a user is connected to the network and only messages to one user at a time, please help

+4
source share
1 answer
  $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 sending (this will be done in your case using the SQL statement). The $ status is also created as you want ... Also $ result if it successfully returns an array containing the status identifier.

I hope this helps

+2
source

All Articles