作为页页的Facebook图形API的PHP SDK发布 [英] Facebook Graph API PHP SDK posting on page as page

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

问题描述

这是最后的尝试,使用PHP,如果失败的话,我会跟JS试试。所以我的目标是张贴FB页的网页名称,通过PHP的:这就是我想要得到

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

但我得到如下所示照片。此外,它仅可见此配置文件(不是朋友/ PPL谁喜欢/等)。

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

这是我目前的code

This is my current code

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-&GT; API('/ ME /账户')键,您会收到一个令牌背面(与页面信息一起),您可以用它来发布页面的作为的页面。

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图形API的PHP SDK发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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