You are here

protected function SocialFacebookFormatter::getPostId in Open Social 7

Parse post URL and get post ID.

Parameters

string $url: Facebook post URL.

Return value

string Post ID.

1 call to SocialFacebookFormatter::getPostId()
SocialFacebookFormatter::getData in includes/social_comments.facebook.inc

File

includes/social_comments.facebook.inc, line 87
Facebook class

Class

SocialFacebookFormatter
@file Facebook class

Code

protected function getPostId($url) {
  $id = $uid = '';
  if (is_string($url)) {

    // Get URL path.
    $url = parse_url($url);
    if (!empty($url['path'])) {
      $parts = explode('/', $url['path']);

      // Get user ID.
      $username = $parts[1];
      $response_url = url('https://graph.facebook.com/' . $username, array(
        'query' => array(
          'access_token' => $this->access_token,
        ),
      ));
      $data = drupal_http_request($response_url);
      if ($data) {
        $data = drupal_json_decode($data->data);
        $uid = $data['id'];
      }
      $id = $uid;
      $id .= '_' . end($parts);
    }
  }
  return $id;
}