0

我在 facebook 中创建了一个应用程序,并且在 php sdk 之间,我可以在我的个人资料上发布我网站的文章。

现在,我想在我的粉丝专页中发布我的文章,而不是在我的 prfile 中。我怎么能这样做?

这是我使用的代码,与 facebook 开发人员中的示例没有太大区别:

    // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('facebook.php');


  $config = array(
    'appId' => 'xxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxx',

  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();


?>


  <?
    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 {
        $access_token = $facebook->getAccessToken();  
        $page_id='xxxxxxxxxxxxxx';   
        $ret_obj = $facebook->api('/me/feed', 'POST',
                                    array(
                                      'link' => $link,
                                      'message' => $titolo,
                                      'picture' => 'http://xxxxxxxxxxxxxxxxxx',
                                      'name' => 'Ecosport',
                                      'access_token' => $access_token
                                 ));
        echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';

      } 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( array(
                       'scope' => 'publish_stream'

                       )); 

        header("location:$login_url");             


        error_log($e->getType());
        error_log($e->getMessage());
      }   
      // Give the user a logout link 

      $id_articolo=$_GET['id_articolo'];

      header("location:xxxxxxxxxx");

      /*echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';*/
    } else {

      // No user, so print a link for the user to login
      // To post to a user's wall, we need publish_stream permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );

      header("location:$login_url");

      /*echo 'Please <a href="' . $login_url . '">login.</a>';*/

    } 

  ?>

显然,“xxxx”用于隐私。我把这个“$facebook->api('/me/feed',......”改成这个“$facebook->api('/$page_id/feed',...... ” 但什么都没有。我不能在我的粉丝专页上发布我的文章。

你能帮助我吗?

非常感谢。

4

1 回答 1

0

您需要请求manage_pagespublish_stream权限。然后调用 /me/accounts 以获取用户管理的帐户(又名页面)列表。该帐户列表中的每个帐户都将具有与之关联的访问令牌。该访问令牌很特殊,需要用于新建 facebook api 的实例。一旦你这样做了,发布到页面墙与发布到用户的墙相同(即 /me/feed)

于 2011-12-30T01:28:14.803 回答