使用 PHP 管理 Facebook 页面

发布于 2024-11-04 09:29:40 字数 307 浏览 0 评论 0原文

我希望使用粉丝页面将我当前的网站与 Facebook 更深入地集成(注意:我确实注意到 Facebook 支持的 Open Graph 协议,但我希望创建一个网站范围的粉丝页面)。
我知道您可以使用 Facebook 创建和管理粉丝专页,但我正在寻找一种使用 PHP 脚本来创建和管理粉丝专页的方法 - 例如,发布到粉丝专页墙、使用粉丝专页创建事件,并且理想情况下 - 创建辅助内容动态粉丝页面。
在浏览了 Facebook 的开发人员部分后,我没有找到使用 Facebook API 从外部执行这些任务的方法。
所以我的问题是:你将如何实现这一目标?

谢谢!

I'm looking to integrate my current website more deeply with Facebook using a Fan Page (notice: I did noticed the Open Graph protocol that Facebook support but i'm looking to create a website-wide fan page).
I know that you can create and manage Fan Pages using Facebook, but I'm looking for a way to do that using a PHP script - for example, post to the Fan Page wall, create events using the Fan Page and ideally - create secondary Fan Pages on the fly.
After looking around in Facebook's developer section I didn't find a method to do those tasks from outside using the Facebook API.
So my question is: how would you accomplish that?

Thanks!

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

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

发布评论

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

评论(1

身边 2024-11-11 09:29:40

向主页发布帖子和创建活动都是相对简单的任务。您可以使用 Graph API 来执行此操作。

具体查看有关发布的区域。它为您提供了发布工作原理的总体概述,并且这可以应用于整个图表。

此外,有关 Graph API 的 Events 部分的文档有一个示例 cURL 帖子,介绍如何创建通过 Graph API 的新事件。

向您的 Facebook 页面发布任何内容都需要您拥有 manage_pages 扩展权限 ,并且获得 offline_access 权限可能也是个好主意。

发布到页面墙和创建事件(在 php 中)的示例看起来很像这样:

<?php

require 'facebook.php';

$fb = new Facebook(array(
    'appId' => FB_APP_ID,
    'secret' => FB_APP_SECRET,
    'cookie' => true
));

$your_page_id = '123123123';

//get the access token to post to your page via the graph api
$accounts = $fb->api("/me/accounts");
foreach ($accounts['data'] as $account)
{
    if ($account['id'] == $your_page_id)
    {
        //found the access token, now we can break out of the loop
        $page_access_token = $account['access_token'];
        break;
    }
}

try
{
    //publish a story to the page's wall (as the page)
    $post_id = $fb->api("/{$your_page_id}/feed", "POST", array(
        'message' => "Hello to all my fans, I love you!"
        'access_token'  => $page_access_token;
    ));

    echo "Post published. ID: {$post_id}<br>";

    //create a new event.
    $event_id = $fb->api("/{$your_page_id}/events", "POST", array(
        "name"  => "My Totally Awesome Event, You Better Show UP!",
        "start_time" => time(), //it starts now...duh!
        "location"  => "Anywhere, USA"
    ));

    echo echo "Event created. ID: {$event_id}<br>";
}
catch (Exception $e)
{
    var_dump($e);
}

对于动态创建页面,唯一的方法是使用 开放图协议。这里唯一的限制是页面必须具有唯一的 URL。因此,您可以为每个开放图谱对象分配一个唯一的 ID,并为它们提供一个类似 http://www.mysite.com/pages?id=123456 的 URL。这将让您输出在 FB 上生成页面所需的 Open Graph 标签。然后,您可以在有人点赞后使用 Graph API 获取 Open Graph 对象的 ID,如下所示:http://graph.facebook.com/?ids=http://www.mysite.com/pages ?id=123456

您可以按照与发布到标准 Facebook 页面相同的方式发布到这些开放图谱对象。

希望有帮助!

Publishing posts to your Page, and creating Events, are both relatively trivial tasks. You can use the Graph API to do that.

Check out the area about Publishing specifically. It gives you the general overview of how publishing works, and this can be applied all over the Graph.

Also, the documentation about the Events portion of the Graph API has an example cURL post for how to create a new event via the Graph API.

Posting anything to your Facebook page is going to require you have the manage_pages extended permission, and it's probably a good idea to get the offline_access permission also.

An example of both posting to your Page wall and creating an event (in php) would look a lot like this:

<?php

require 'facebook.php';

$fb = new Facebook(array(
    'appId' => FB_APP_ID,
    'secret' => FB_APP_SECRET,
    'cookie' => true
));

$your_page_id = '123123123';

//get the access token to post to your page via the graph api
$accounts = $fb->api("/me/accounts");
foreach ($accounts['data'] as $account)
{
    if ($account['id'] == $your_page_id)
    {
        //found the access token, now we can break out of the loop
        $page_access_token = $account['access_token'];
        break;
    }
}

try
{
    //publish a story to the page's wall (as the page)
    $post_id = $fb->api("/{$your_page_id}/feed", "POST", array(
        'message' => "Hello to all my fans, I love you!"
        'access_token'  => $page_access_token;
    ));

    echo "Post published. ID: {$post_id}<br>";

    //create a new event.
    $event_id = $fb->api("/{$your_page_id}/events", "POST", array(
        "name"  => "My Totally Awesome Event, You Better Show UP!",
        "start_time" => time(), //it starts now...duh!
        "location"  => "Anywhere, USA"
    ));

    echo echo "Event created. ID: {$event_id}<br>";
}
catch (Exception $e)
{
    var_dump($e);
}

As for creating Pages on the fly, the only way you can do that is by using the Open Graph Protocol. The only restriction here is that pages have to have unique URLS. So you can assign each of your Open Graph objects a unique ID, and give them a URL like http://www.mysite.com/pages?id=123456. This will let you output the Open Graph tags required to generate the page on FB. You can then use the Graph API to get the ID of the Open Graph object after someone likes it like so: http://graph.facebook.com/?ids=http://www.mysite.com/pages?id=123456.

You can publish to these Open Graph objects the same exact way you'd publish to a standard Facebook Page.

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文