简体   繁体   中英

Facebook PHP API: mentioning page through @[PAGE_ID]

I guess I have read all past posts about the argument, but I was wondering if something has changed on topic.

Is it now possible to mention a page inside a message text using Facebook PHP SDK? Something like this:

$post_params = array(
   'access_token' => PAGE_TOKEN,
   'message' => 'This is a message tagged to @[PAGE_ID]
);
$postStream = $this->facebook->api("/" . PAGE_ID . "/feed", 'post', $post_params);

I am referring to this page: https://developers.facebook.com/docs/opengraph/guides/tagging/

Actually, so far, I solved the problem the following way:

1) "Normalize" the page name through a regex replacement of possible "facebook related" uri

$replacePattern = '((https|http)?(:\/\/)?(www\.)?(facebook\.com)?(\/)?)';
$page_name = preg_replace($replacePattern, '', $page_name);
$page_name = 'https://www.facebook.com/' . $page_name;

2) Make a call to Facebook API using the "normalized" uri:

$fql = "SELECT id, name FROM profile WHERE id in (SELECT id FROM object_url WHERE url='" . $page_name . "')";
    $param = array(
        'method'        => 'fql.query',
        'query'         => $fql,
        'callback'      => ''
    );
    $response = $facebook->api($param);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM