如何通过 php 获取 Facebook 页面 id?

发布于 2024-11-08 16:51:09 字数 129 浏览 6 评论 0原文

假设我有一个 Facebook 页面链接 http://facebook.com/page_name 并且我不是该页面的管理员。是否可以找到 Facebook ID、页面的个人资料图片和粉丝数?

谢谢!

Suppose i have a facebook page link http://facebook.com/page_name and i am not the admin of the page. Is it possible to find out the facebook id, profile pics of the page and fan count?

Thanks!

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

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

发布评论

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

评论(3

爱她像谁 2024-11-15 16:51:10

通常,您可以执行 http://graph.facebook.com/{page_name} 并收到适当的结果。例如,百事可乐位于 http://www.facebook.com/pepsi,您可以看到该图表API 结果位于 https://graph.facebook.com/pepsi

Typically you can do http://graph.facebook.com/{page_name} and receive the appropriate results. For example, Pepsi is at http://www.facebook.com/pepsi and you can see the graph API results at https://graph.facebook.com/pepsi.

慢慢从新开始 2024-11-15 16:51:10

您可以使用 Facebook SDK for PHP https://github.com/facebook/php-graph-sdk

下面是我的解决方案

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

$pageUrl = 'some_url';  
      FacebookSession::setDefaultApplication('facebookAppId','facebookAppSecret');
    //getting session
    $Session = FacebookSession::newAppSession();
    try
    {
      //validating if session is correct
      $Session->validate();
      //sending request
      $Request = new FacebookRequest($Session, 'GET', '/',
                                      array (
                                        'id' => $pageUrl,
                                      )
                                    );
      $Response = $Request->execute();
      //getting UserGraph object
      $UserObject = $Response->getGraphObject(GraphUser::className());
      //return page id
      return $UserObject->GetId();
    }
    catch (FacebookRequestException $ex)
    {}
    catch (Exception $ex)
    {}

You can use Facebook SDK for PHP https://github.com/facebook/php-graph-sdk

Below my solution

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

$pageUrl = 'some_url';  
      FacebookSession::setDefaultApplication('facebookAppId','facebookAppSecret');
    //getting session
    $Session = FacebookSession::newAppSession();
    try
    {
      //validating if session is correct
      $Session->validate();
      //sending request
      $Request = new FacebookRequest($Session, 'GET', '/',
                                      array (
                                        'id' => $pageUrl,
                                      )
                                    );
      $Response = $Request->execute();
      //getting UserGraph object
      $UserObject = $Response->getGraphObject(GraphUser::className());
      //return page id
      return $UserObject->GetId();
    }
    catch (FacebookRequestException $ex)
    {}
    catch (Exception $ex)
    {}
星星的轨迹 2024-11-15 16:51:09

FB id 和一些信息:是的。请参阅Graph API 文档

编辑:
从我的应用程序获取 id 的一些代码:

$arg = $_REQUEST['arg'];
if ($arg != ''){

        $arg = str_replace(
                array('http://','www.','facebook.com/','/'),
                '',
                $arg
        );

        $elseID = file_get_contents('https://graph.facebook.com/?ids='.$arg.'&fields=id');
        $elseID = json_decode($elseID,true);
        $elseID = $elseID[$arg]['id'];
}

FB id and some informations: yes. See Graph API docs.

edit:
Some code to get id from my app:

$arg = $_REQUEST['arg'];
if ($arg != ''){

        $arg = str_replace(
                array('http://','www.','facebook.com/','/'),
                '',
                $arg
        );

        $elseID = file_get_contents('https://graph.facebook.com/?ids='.$arg.'&fields=id');
        $elseID = json_decode($elseID,true);
        $elseID = $elseID[$arg]['id'];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文