Facebook Graph API PHP SDK 作为页面发布在页面上 [英] Facebook Graph API PHP SDK posting on page as page

查看:26
本文介绍了Facebook Graph API PHP SDK 作为页面发布在页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 的最后一次尝试,如果失败,我会尝试 JS.所以我的目标是通过 PHP 在 FB 页面上以页面名称"的形式发布:这就是我想要的

It's final try with PHP, if it fails, I'll try with JS. So my goal is to post on FB page as "Page name" through PHP: this is what I want to get

但我得到的只是下面的图片.此外,它仅对这个个人资料可见(对喜欢/等的朋友/人不可见).

But all I get is shown pic below. Also, it's visible ONLY to this profile (not to friends/ppl who like/etc.).

这是我当前的代码

function post_facebook($data=null, $redir = null){
        $result = "";
        require_once (ROOT. "/apps/configuration/models/ConfigurationItem.php");
        require_once (ROOT . "/components/facebook/facebook.php");

        $this->ConfigurationItem = new ConfigurationItem($this->getContext());

        $row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_login');
        $apiid=$row['value']; <= Correct apiid

        $row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_pass');
        $secret=$row['value']; <= Correct secret key

        $facebook = new Facebook(array(
          'appId'  => $apiid,
          'secret' => $secret,
          'cookie' => true,
        ));

        $session = $facebook->getSession();
        $me = null;
        if ($session) {
            try {
                $uid = $facebook->getUser();
                $me = $facebook->api('/me');
            } catch (FacebookApiException $e) {
                error_log($e);
            }
            $message=$data['facebook_text'];
            $attachment = array(
                'message' => $data['facebook_text'],
                'name' => $data['name'],
                'link' => $this->getLinkToLatestNews(),
                'description' => '',
            );

            try {
                $facebook->api('/PAGE ID/feed/', 'post', $attachment);
                $result = "Facebook: Sent";
            } catch (FacebookApiException $e) {
                $result = "Facebook: Failed";
                error_log($e);
            }
        } else {
            $login_url = $facebook->getLoginUrl();
            header("Location: ".$login_url);
            exit;
        }

        echo $result;
        exit;
        //return $result;

    }

我做错了什么?我在 API 文档/顶级谷歌结果中找不到任何内容,仅适用于 JS.感谢帮助!

What I'm doing wrong? I couldn't find anything in API documentation/top google results, only for JS. Thanks for help!

推荐答案

您需要确保为用户请求manage_pages"权限.一旦你知道你可以做 $facebook->api('/me/accounts') 并且你会收到一个令牌(以及页面信息),你可以使用它在页面上发布作为页面.

You'll need to make sure you're requesting the 'manage_pages' permission for the user. Once you've got that you can do $facebook->api('/me/accounts') and you'll receive a token back (along with the page info) that you can use to post on the page as the page.

这篇关于Facebook Graph API PHP SDK 作为页面发布在页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆