Facebook PHP SDK v3.1.1 - 当页面离线时在页面墙上发布消息

发布于 2024-12-27 02:13:07 字数 743 浏览 4 评论 0原文

我正在尝试在页面墙上发布一条消息作为页面本身,而无需任何用户连接。

目前,第一部分工作正常,但我需要一个连接的用户来完成它。我听说我需要一个 seesion ID 才能离线执行此操作,但我不知道如何获取它以及如何使用它。

现在,我的代码是:

$facebook = new Facebook(array('appId'  => $appID, 'secret' => $appSecret));
$user = $facebook->getUser();

try 
{
    $pageInfo = $facebook->api("/{$pageID}?fields=access_token");
    if(!empty($pageInfo['access_token'])) 
    {
        $args = array(
            'access_token'  => $pageInfo['access_token'],
            'message'       => $message
        );
        $postID = $facebook->api("/{$pageID}/feed", 'post', $args);
    }
} 
catch (FacebookApiException $e) 
{
    echo '<pre>'; var_dump($e); echo '</pre>';
    $user = null;
}

I'm trying to post a message on a page's wall as the page itself without any user connected.

For now, the first part works fine, but I need a connected user to do it. I've heard I need a seesion ID to do it offline, but I don't know how to get it and how to use it.

For now, my code is:

$facebook = new Facebook(array('appId'  => $appID, 'secret' => $appSecret));
$user = $facebook->getUser();

try 
{
    $pageInfo = $facebook->api("/{$pageID}?fields=access_token");
    if(!empty($pageInfo['access_token'])) 
    {
        $args = array(
            'access_token'  => $pageInfo['access_token'],
            'message'       => $message
        );
        $postID = $facebook->api("/{$pageID}/feed", 'post', $args);
    }
} 
catch (FacebookApiException $e) 
{
    echo '<pre>'; var_dump($e); echo '</pre>';
    $user = null;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤凫 2025-01-03 02:13:07

您需要设置offline_access权限,然后您就可以执行您需要的操作。看看这个,它会告诉你该怎么做: http://eagerfish.eu/using-facebook-off-line-access-to-post-on-users-wall/

You need the offline_access permission set, then you can do what you need. Check this out it will show you what to do: http://eagerfish.eu/using-facebook-off-line-access-to-post-on-users-wall/

漆黑的白昼 2025-01-03 02:13:07

Facebook将删除offline_access权限,他们现在允许选择使用具有长期过期时间的access_tokens。

Facebook will be removing offline_access permission, they are now allowing the option to use access_tokens with a long-lived expiration time.

风为裳 2025-01-03 02:13:07

使用 publish_stream 权限。

使您的应用能够将内容、评论和点赞发布到用户的信息流以及用户朋友的信息流中。有了此权限,您可以随时将内容发布到用户的源,而无需进行离线访问。但请注意,Facebook 推荐用户发起的共享模式。

除了作为页面(而不是用户)发布请求manage_pages

var $permissions_needed = 'manage_pages,publish_stream';

如何登录:

$this->login_url = $facebook->getLoginUrl(
        array(
            'scope' => $this->permissions_needed,
            'display' => 'page'
        )
);

Use publish_stream permissions.

Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. With this permission, you can publish content to a user's feed at any time, without requiring offline_access. However, please note that Facebook recommends a user-initiated sharing model.

Besides to post as the page (not user) ask for manage_pages.

var $permissions_needed = 'manage_pages,publish_stream';

How to login:

$this->login_url = $facebook->getLoginUrl(
        array(
            'scope' => $this->permissions_needed,
            'display' => 'page'
        )
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文