作为其他Facebook页面B用户发布到Facebook A页面



寻找数小时后,我找不到这个问题的答案。希望有人可以帮助我。我正在使用最新的Facebook PHP SDK(v.3.2.0)。

我有一个公司的粉丝页面(A页),该公司的几个人也有粉丝页面(B,C,C,D等)。问题是我们要将页面B(和C和D)的帖子发布到A页,但发件人(POST用户)应为Page用户b。

您可以将其发布到页面墙A作为另一页用户b?

我已经尝试了所有内容,并且有以下工作:

  • 我有一个管理用户的访问令牌,该用户是所有页面的管理员
  • 我有一个扩展的访问令牌,能够自动执行60天的请求
  • 我有一个来自/me/帐户请求的所有页面的页面令牌
  • 我有一个通过/[pag-id]/feed

最后一部分是在数组上循环,以张贴到A页的墙壁上,作为用户B,C或D。

我将发布请求发送到/[Page-id-page-a]/带有消息和页面的页面。

undureck oauthexception :(#200)演员为页面的帖子也不能包括target_id

将作为页面用户B发布到页面B的墙壁上正常工作。将作为页面用户B发布到页面A不会。该文档尚不清楚是否应该使用,但是从Facebook UI可以使用。

希望有人可以将我指向正确的方向。我使用的代码下面是想要使用它的任何人。

<?php
/* ************************
* Helper functions
************************ */
function sortbykey($a, $b) {
  return $a['time'] - $b['time'];
}
/* ************************
* Start app
************************ */
// Initialize Facebook
require_once("facebook.php");
$facebook = new Facebook(array('appId' => '<appID>','secret' => '<appSecret>'));
// Get facebook user (if possible)
$user_id = $facebook->getUser();
$login_params = array(
  'scope' => 'manage_pages,publish_stream',
  'redirect_uri' => '<app_url>/index.php'
);
if($user_id) {
  // We have a user ID, so probably a logged in user.
  // If not, we'll get an exception, which we handle below.
  try {
    // Get user profile and extended access tokens for requests
    $user_profile = $facebook->api('/me','GET');
    $facebook->setExtendedAccessToken();
    $access_token = $facebook->getAccessToken();
  } catch(FacebookApiException $e) {
    // If the user is logged out, you can have a 
    // user ID even though the access token is invalid.
    // In this case, we'll get an exception, so we'll
    // just ask the user to login again here.
    $login_url = $facebook->getLoginUrl($login_params); 
    echo '<div class="login"><a href="' . $login_url . '">login</a></div>';
    error_log($e->getType());
    error_log($e->getMessage());
  }   
} else {
  // No user, print a link for the user to login
  $login_url = $facebook->getLoginUrl($login_params);
  echo '<div class="login"><a href="' . $login_url . '">login</a></div>';
}
if(isset($access_token) && !empty($access_token)){
  // Provide logout options
  $logout_url = $facebook->getLogoutUrl(); 
  echo '<div class="logout"><a href="' . $logout_url . '">logout</a></div>';
  // Get user pages and tokens
  $user_pages = $facebook->api('/me/accounts','GET');
  $page_tokens = array();
  foreach($user_pages['data'] as $page){
    $page_tokens[$page['id']] = $page['access_token'];
  }
  // Set challenger ID's and page ID
  $persons = array('page-ID-B','page-ID-C','page-ID-D');
  $page = 'page-ID-A';
  // Loop over persons and create stream of messages.
  $messages = array();
  foreach($persons as $person){
    $token = $page_tokens[$person];
    $feed = $facebook->api('/'.$person.'/feed','GET');
    foreach($feed['data'] as $status){
      // Add page token to message to post as page and time to sort by
      $status['token'] = $token;
      $status['time'] = strtotime($status['created_time']);
      // Only add messages that aren't imported yet
      if($status['time'] > $_SESSION['lastupdatetime']) {
        $messages[] = $status;
      }
    }
  }
  // Sort by time value in nested array
  usort($messages,"sortbykey");
  // Post messages to timeline
  foreach($messages as $status){
    // Post to MScHALLENGE page based on type
    switch($status['type']){
      case 'status':
      case 'link':
        // Build post data 
        $data = array();
        if(isset($status['message'])) $data['message'] = $status['message'];
        if(isset($status['link'])) $data['link'] = $status['link'];
        // Post to facebook
        if(!empty($data)){
          $data['access_token'] = $status['token'];
          $post = $facebook->api('/'.$page.'/feed','POST',$data);
        }
        break;
    }
    // Save last update time
    $_SESSION['lastupdatetime'] = $status['time'];
  }  
}
?>

这不支持我最近进行了一些测试。即使您是 pagea and pageb的管理员,也不能在pagea上发布为pageb(其中"语音"设置为pageb,并且帖子显示为PageB撰写)。语音(即" pageb")在您管理的页面上工作,并在页面上创建帖子,其语音属于 same same page。至少这就是API当前的行为。

最新更新