如何在facebook的组墙上发帖

时间:2013-03-12 09:35:23

标签: php facebook facebook-graph-api

我想发布组墙。我有“user_groups”和“publish_stream”的许可。还有access_token。

这是我的代码:

                try{
            $statusUpdate = $this->facebook->api('/'.$group_id.'/feed', 'post',
                 array(
                'name' => stripslashes($productname),
                //'caption'=>$caption,
                'message' => $message,
                'description' => $description,
                'picture' => $picture,
                'link'=>$link));

                    $postid =  $statusUpdate['id']; // return id


            } catch (Exception $e){
                        $postid = 0;
                    }
                    return $postid; // return id
    }

当我运行此代码时,我得到一个返回ID,即页面ID。但我的小组墙上没有任何帖子。怎么解决这个?

1 个答案:

答案 0 :(得分:1)

此代码适用于我发布到Facebook页面。

  1. 获取FB页面访问令牌($ value ['access_token'])及其页面ID($ value ['id'])
  2. 填充$ params数组
  3. 使用FB API发布消息3。
  4. 这是一个片段

    foreach ($pages as $key => $value) {
       $params = array(
          'access_token' => $value['access_token'],
           'message' => $message
        );
        // ask facebook api to post the message to the selected page
        $facebook->api()->api( "/" . $value['id'] . "/feed", 'POST', $params );
    }