【问题标题】:I want to post from my site on my fanpage我想在我的粉丝专页上发布我的网站
【发布时间】:2011-12-31 01:52:56
【问题描述】:

我在 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',...... " 但什么都没有。我不能在我的粉丝专页上发布我的文章。

你能帮帮我吗?

非常感谢。

【问题讨论】:

    标签: facebook-graph-api fan-page


    【解决方案1】:

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

    【讨论】:

    • 查看developers.facebook.com/docs/authentication的页面登录部分
    • DMCS,以用户身份发布到粉丝页面。你知道如何让它作为粉丝页面发布到粉丝页面吗?
    • 不,我上面的解释不是作为用户发布到流中,而是作为页面发布,因为它使用 PAGE 的访问令牌。
    猜你喜欢
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    相关资源
    最近更新 更多