douju1852 2015-08-21 11:21
浏览 135
已采纳

Facebook页面上的PHP自动发布

I am trying to auto post on Facebook page using my app it works fine if I replace my-page-numeric-id with my profile numeric id, but when I put my page numeric id instead of my-page-numeric-id and put valid access token it won't publish on Facebook page I tried to submit review permission that are as follow "manage_pages, publish_actions" but Facebook team mentioned that you don't need it all because you own this page and your currently admin of it, these permission are necessary when any other person need to authorize with your app. Now my question is, my code works perfectly for publishing post on my profile's wall but i am unable to auto post on my page what is the problem behind it i am unable to figure out here is my code

<?php
 require_once 'src/facebook.php';
class FacebookApi {

    var $consumer;
    var $token;
    var $method;
    var $http_status;
    var $last_api_call;
    var $callback;
    var $connection;
    var $access_token;

    function __construct($data){
        $config = array();
        $config['appId'] = $data['consumer_key'];
        $config['secret'] = $data['consumer_secret'];

        $this->connection = new Facebook($config);

    }

    function share($title, $targetUrl, $imgUrl, $description, $access_token){

        $this->connection->setAccessToken($access_token);

        $params["access_token"] = $access_token;
        if(!empty($title)){
            $params["message"] = $title;
            $params["name"] = $title;
        }
        if(!empty($targetUrl)){
            $params["link"] = $targetUrl;
        }
        if(!empty($imgUrl)){
            $params["picture"] = $imgUrl;
        }
        if(!empty($description)){
            $params["description"] = $description;
        }

        // post to Facebook
        try {
          $ret = $this->connection->api('/my-page-numeric-id/feed', 'POST', $params);
        } catch(Exception $e) {
          $e->getMessage();
        }

        return true;
    }

    function getLoginUrl($params){
        return $this->connection->getLoginUrl($params);
    }

    function getContent($url) {
        $ci = curl_init();
        /* Curl settings */
        curl_setopt($ci, CURLOPT_URL, $url);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ci, CURLOPT_HEADER, false);
        curl_setopt( $ci, CURLOPT_CONNECTTIMEOUT, 10 );

        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);

        $response = curl_exec($ci);
        curl_close ($ci);
        return $response;
      }
}

$access_token = 'long-live-token-here';
$facebookData = array();
$facebookData['consumer_key'] = 'app-id-here';
$facebookData['consumer_secret'] = 'app-secret-here';

$title = "Demo Content Posted on Timeline";
$targetUrl = "http://www.demo_url.com/1234-post";
$imgUrl = "http://www.demo_url.com/1234-post-image.png";
$description = "demo_description_here"; 

$facebook = new FacebookApi($facebookData);
$facebook->share($title, $targetUrl, $imgUrl, $description, $access_token);

?>
  • 写回答

2条回答 默认 最新

  • dongpo1846 2015-08-21 14:44
    关注

    With API v2.3, they have split the publishing permission into two separate ones:

    • publish_actions is for anything you want to publish as a user

    • if you want to publish as a page however, you need publish_pages permission (in addition to manage_pages)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c