簡體   English   中英

使用他們的離線令牌發布到Facebook用戶的牆

[英]Posting to a facebook user's wall using their offline token

大家好,我有一個遵循所有規則的應用程序...我想每天一次發布到用戶的Facebook牆上。 我已經在那里存儲了Facebook ID及其離線令牌。 可以說我有5個結果,我想發布到所有牆壁上,而不僅僅是一個,這是我的腳本

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

當然,我為此有一個連接,以便每個人都知道該腳本在用戶在線時發布到1個隨機選擇的牆,但是我希望腳本在離線時發布並發布給所有用戶

這就是我如何在那里脫機令牌

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

就像我說過的,它僅在用戶在線時發布,並且一次僅發布給1個用戶,請幫助

    $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
      }

這是操作的簡化版本...但是,您可以使用要發布到的用戶定義$ uid(在您的情況下,這將通過SQL語句完成)。 $ status也會隨您的意願創建...如果成功返回包含狀態ID的數組,則還會返回$ result。

我希望這有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM