获取 Facebook 粉丝页面 ID

发布于 2024-09-07 15:03:14 字数 123 浏览 3 评论 0原文

我已经获得了创建给定页面的用户的 Facebook 用户 ID。现在我需要获取页面 ID 以在我的网站中显示类似的框。

不同的用户有自己的Facebook页面;不过,我知道如何获取他们的 Facebook 用户 ID

I've got the Facebook user ID of the user who created a given page. Now I need to get the page ID to display like box in my website.

Different users have their own Facebook pages; however, I know how to get their Facebook user IDs

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

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

发布评论

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

评论(9

逆流 2024-09-14 15:03:14

您可以将页面 URL 中的 www 替换为 graph。例如可口可乐页面的 id http://graph.facebook.com/cocacola (第一个值)。

You can replace www to graph in the page URL. For example id of the Coca-Cola page http://graph.facebook.com/cocacola (first value).

对你而言 2024-09-14 15:03:14

粉丝页面的 URL 中将包含 ID。例如,Stack Overflow 粉丝页面

http://www.facebook.com/pages/Stack-Overflow/105665906133609

ID 为 105665906133609

有些页面有别名,分别是也可用作 ID。例如,海军陆战队的粉丝页面是

http://www.facebook.com/marinecorps

所以 ID 是 ma​​rinecorps

或者,您可以使用 <还有一个 href="http://developers.facebook.com/docs/reference/plugins/like" rel="noreferrer">文档页面。

The URL to the fan page will have the ID in it. For example, the Stack Overflow fan page

http://www.facebook.com/pages/Stack-Overflow/105665906133609

The ID is 105665906133609

Some pages have aliases, which are also usable as the ID. For example, the Marine Corps' fan page is

http://www.facebook.com/marinecorps

So the ID is marinecorps

Alternatively, you can use the generator on the documentation page as well.

偏爱自由 2024-09-14 15:03:14

页面 ID 包含在签名的请求中。这是拜伦的 Facebook 页面更新帖子的更新版本。

$facebook = new Facebook();

$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request['page']['id'];

echo 'page id is ' . $page_id . ' AAAAAAAAAAWWWWWWW YYYYYYEEEEEEEEAAAAAAAAAAAA!';

The page id is included in the signed request. Here an updated version of byron's post for facebook's page update.

$facebook = new Facebook();

$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request['page']['id'];

echo 'page id is ' . $page_id . ' AAAAAAAAAAWWWWWWW YYYYYYEEEEEEEEAAAAAAAAAAAA!';
赠我空喜 2024-09-14 15:03:14

这可以使用新的 php sdk 进行工作,

$page_id = null;
$facebook = new Facebook();
try {
    $signed_request = $facebook->getSignedRequest();
    $page_id = $signed_request['profile_id'];
} catch (FacebookApiException $e) {
    error_log($e);
}

请注意,我对此感到不安,因为我实际上正在寻找的是页面创建者的用户 ID,因为我需要在选项卡上显示该用户创建的内容。这曾经是可能的,但我认为现在不可能了。 kasun,你如何获得页面创建者的ID?

this works using the new php sdk

$page_id = null;
$facebook = new Facebook();
try {
    $signed_request = $facebook->getSignedRequest();
    $page_id = $signed_request['profile_id'];
} catch (FacebookApiException $e) {
    error_log($e);
}

please note that i'm upset that this works, because what i'm actually looking for is the user id of the page creator since I need to display content created by that user on the tab. this used to be possible, but i don't think it is anymore. kasun, how are you getting the id of the page creator?

终弃我 2024-09-14 15:03:14
$pages = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT page_id FROM page_admin WHERE uid = '.$uid.''
));

$uid 是 FB 用户的个人资料 ID#!使用 PHP SDK 进行 Fql 查询

$pages = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT page_id FROM page_admin WHERE uid = '.$uid.''
));

$uid being the profile id# of the FB user! Fql query using PHP SDK

柳若烟 2024-09-14 15:03:14

Facebook 后,转到 http://www.facebook.com/insights/

登录 右上角的绿色按钮(“洞察您的域”)
选择您页面的下拉值
瞧,你看到了 page_id

(我在 Facebook 论坛上看到了这个)

goto http://www.facebook.com/insights/ after you logged in to your facebook

press the green button on top right ( "insight for your domain")
select the drop down value for your page
voila, you see the page_id

(I saw this on facebook forum)

沉溺在你眼里的海 2024-09-14 15:03:14

以下是您可以在 facebook sdk 中添加的功能列表。
适用于图形 api 和其余 api。

/*
    Custom functions to get fan page related information
*/
function getSignedData()
{
    if(isset($this->signedData) && !empty($this->signedData))
        return $this->signedData;

    if(!isset($_REQUEST["signed_request"]))
        return false;

    $signed_request = $_REQUEST["signed_request"];

    if(empty($signed_request))
        return false;

    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

    if(empty($data))
        return false;

    $this->signedData = $data;



    return $data;
}

/*
    Return fan page id, Only return fanpage id for 1st (landing) page of application.
*/
function getFanPageId()
{
    if(!$data = $this->getSignedData())
    {
        return false;
    }
    if(isset($data["page"]["id"]))
        return $data["page"]["id"];

    return false;
}

/*
    Only returns userid, if user has authenticated application
*/
function getFanPageUserId()
{
    if(!$data = $this->getSignedData())
    {
        return false;
    }

    if(isset($data["user_id"]))
    {
        return $data["user_id"];
    }

    return false;
}

/*
Check if visiting user is fan page admin
*/
function checkFanPageAdmin()
{
    if(!$data = $this->getSignedData())
        return false;

    if(isset($data["page"]["admin"]) && $data["page"]["admin"] == 1)
        return true;

    return false;
}

Here are list of functions which you can add in facebook sdk.
Works for both graph api and rest api.

/*
    Custom functions to get fan page related information
*/
function getSignedData()
{
    if(isset($this->signedData) && !empty($this->signedData))
        return $this->signedData;

    if(!isset($_REQUEST["signed_request"]))
        return false;

    $signed_request = $_REQUEST["signed_request"];

    if(empty($signed_request))
        return false;

    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

    if(empty($data))
        return false;

    $this->signedData = $data;



    return $data;
}

/*
    Return fan page id, Only return fanpage id for 1st (landing) page of application.
*/
function getFanPageId()
{
    if(!$data = $this->getSignedData())
    {
        return false;
    }
    if(isset($data["page"]["id"]))
        return $data["page"]["id"];

    return false;
}

/*
    Only returns userid, if user has authenticated application
*/
function getFanPageUserId()
{
    if(!$data = $this->getSignedData())
    {
        return false;
    }

    if(isset($data["user_id"]))
    {
        return $data["user_id"];
    }

    return false;
}

/*
Check if visiting user is fan page admin
*/
function checkFanPageAdmin()
{
    if(!$data = $this->getSignedData())
        return false;

    if(isset($data["page"]["admin"]) && $data["page"]["admin"] == 1)
        return true;

    return false;
}
变身佩奇 2024-09-14 15:03:14

我假设您是用户,并且您想要您作为管理员的页面的页面 ID。

获取 id 相当简单。

首先,您需要获取与用户 ID 关联的所有页面的列表:

$fanpages = $facebook->api('me/accounts?access_token='.$accessToken);

然后,您将执行如下循环:

foreach ($fanpages['data'] as $fanpage)
{
echo "<br />Fan Page Name: ".$fanpage['name'] . " ID: ".$fanpage['id'];
}

这将列出与该 id 关联的所有页面。

有关 $fanpage 数组元素的完整列表,请查看此处:

https: //developers.facebook.com/docs/reference/api/page/

I am presuming that you are the user and you want the page id of a page that you are the admin of.

To get the id is fairly straightforward.

First, you need to get a list of all pages associated with the user id:

$fanpages = $facebook->api('me/accounts?access_token='.$accessToken);

You would then do a loop like:

foreach ($fanpages['data'] as $fanpage)
{
echo "<br />Fan Page Name: ".$fanpage['name'] . " ID: ".$fanpage['id'];
}

That would list all the pages associated with the id.

For a full list of the elements of the $fanpage array, take a look here:

https://developers.facebook.com/docs/reference/api/page/

风为裳 2024-09-14 15:03:14

这些答案似乎不再有效,因为图表现在需要大多数(如果不是全部)请求的访问令牌。

这是一个可行的解决方案,只需要输入 Facebook 页面 URL。

它的作用是接收 HTML 形式的 Facebook 页面,并通过正则表达式查找具有数值的 JSON entity_id。该值是页面的 ID。该解决方案肯定不能保证永远有效,因为页面内容可能会发生变化

/**
 * @param string $facebookUrl
 * @return null|string
 */
function get_facebook_id($facebookUrl)
{
    $facebookId = null;
    $fbResponse = @file_get_contents($facebookUrl);
    if($fbResponse)
    {
        $matches = array();
        if (preg_match('/"entity_id":"([0-9])+"/', $fbResponse, $matches))
        {
            $jsonObj = json_decode("{" . $matches[0] . "}");
            if($jsonObj)
            {
                $facebookId = $jsonObj['entity_id'];
            }
        }
    }
    return $facebookId;
}

These answers don't seem to work anymore since the graph now requires an access token for most if not all requests.

Here's a working solution that only requires as input the facebook page URL.

What this does is receives the facebook page as HTML and looks through(via regex) for a JSON entity_id that has a numeric value. This value is the page's ID. This solution is surely not guaranteed to work forever since page content may change

/**
 * @param string $facebookUrl
 * @return null|string
 */
function get_facebook_id($facebookUrl)
{
    $facebookId = null;
    $fbResponse = @file_get_contents($facebookUrl);
    if($fbResponse)
    {
        $matches = array();
        if (preg_match('/"entity_id":"([0-9])+"/', $fbResponse, $matches))
        {
            $jsonObj = json_decode("{" . $matches[0] . "}");
            if($jsonObj)
            {
                $facebookId = $jsonObj['entity_id'];
            }
        }
    }
    return $facebookId;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文