0

I'm extracting wall posts from a facebook group feed, but the only thing I'm interested in is the youtube embed id's. Studying Facebook's Graph API, I can't see if there's an easier way of just extracting the youtube embeds directly?

My current solution seems a bit heavy as there are over 3000 posts on the group wall.

Update: As far as I can see, I need to get the metadata as youtube embed links aren't actually shown in the feed.

This is how I parse the group feed, any idea as how I would go about getting the metadata attachment for a youtube link here?

require '../src/facebook.php';

$appId = 'appid'; //appid from facebook
$secret = 'secretid'; //secret from facebook
$groupId = 'groupid'; //facebook groupid

$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $secret,
  'cookie' => true
));

$response = $facebook->api('/'.$groupId.'/feed', array('limit' => 600, 'fields'=>'from,message, created_time'));    
print "<div class='facebook-feed-title'>Facebook Feed</div>";
foreach ($response['data'] as $value) {
    print "<div class='facebook-from'><a href='http://www.facebook.com/home.php?#!/profile.php?id=".$value['from']['id']."'>".$value['from']['name']."</a> wrote:</div>";
    print "<div class='link'>".$value['message']."</div>";        
}
PHearst
  • 751
  • 6
  • 29

2 Answers2

1

In graph api response feed, for each post there is a parameter call 'type'. For videos it will be

"type": "video"

you can get the video link from 'source' parameter.Then add that link to you tube embed code.

<iframe width="420" height="315" src="Youtube_source_link" frameborder="0" allowfullscreen></iframe>
  • As far as I can see, this only gets links that are visible inline in the message. If the Youtube url is embedded, then the url is still not visible in the output. But feel free to show me a code example of how you think this would work. See my original post above for sample code. – PHearst Apr 09 '12 at 12:41
  • I think the issue is with 'fields'=>'from,message, created_time'. If you remove 'fields' from your request parameters you will able to see all the data from the feed . – Kasun Karunathilake Apr 10 '12 at 04:07
  • Nope, tried with FQL as well, but posts with embedded youtube urls and no url in the message itself will not show up. According to [this post] (http://stackoverflow.com/questions/3354489/posting-attachment-facebook-graph-api) the Graph API doesn't yet support requests for attachments (like youtube urls). I'll be very interested to hear any workarounds, but I think I'll just scrape the existing links and make the users leave the urls in the messagefield. – PHearst Apr 10 '12 at 12:56
0

Though this question is 3 years old, I struggled with this last night, and came upon this thread.

I found the solution, so I'm posting here, in case anyone else finds thread.

In API 2.4 you might not get all fields back, but you can explicitly as for specific fields. e.g.: /%post-id%?fields=link,created_time will return the created time and link fields of a post - including the embedded youtube link.

Rereading the code above, I think that adding "link" to the fields clause might have been enough...

Eyal Naveh
  • 61
  • 2