user975343
user975343

Reputation:

Looking for effiicient way to pull data from facebook graph api

I've been recently working with facebook graph api , when I'm pulling user's recents status messages using https://graph.facebook.com/me/statuses?access_token=... all I get is a long list which contains details about the status content, and I want to pull the names of people who liked the status.

The current solution I've been thinking about is using preg match, I'd like to know if you guys have any other suggestions,

Thanks in advance

Upvotes: 0

Views: 336

Answers (1)

Martin Bean
Martin Bean

Reputation: 39389

I'm not sure what path you're using, but you can fetch the list of users who like a particular status update by requesting the likes connection on an update.

For example, requesting https://graph.facebook.com/10150710880081168/likes yields something like the following for me:

{
  "data": [
    {
      "id": "276700623", 
      "name": "Vikki Carter"
    }, 
    {
      "id": "1514365200", 
      "name": "Darren Bean"
    }, 
    {
      "id": "539760281", 
      "name": "Ian Sidaway"
    }
  ], 
  "paging": {
    "next": "https://graph.facebook.com/10150710880081168/likes?format=json&limit=25&offset=25&__after_id=539760281"
  }
}

You'll need the ID of the status update, but also the user_status permission from the logged-in user.

EDIT: Iterating over the returned data and assigned users into an array:

<?php

$result = $facebook->api('[status_id]/likes');

$names = array();
foreach ($result['data'] as $user) {
    $names[] = $user['name'];
}

You should now have an array of names of users who liked the status in question.

Upvotes: 1

Related Questions