0

I have the following code

$taggable = (new FacebookRequest(
$session,
'GET',
'/me/friends'
))->execute()->getGraphObject()->asArray();

echo '<pre>' . print_r( $taggable, 1) . '</pre>';

I am trying to get the id of the list of friends who is also using the app, so that the user can tag the photo with these friends. Right now the code prints the friends who are also using the app, their name and id. I want to get the id of a friend to sub into the parameters of "tags", however the getProperty('id') doesn't work and gives me an error. I am new to facebook api so I am unfamiliar with the syntax.

How do I get the id of the friend to sub into:

 'tags' => '[{\'tag_uid\': \'testing\'}]',

Thanks

4

1 回答 1

2

进行 API 调用后,您将获得以下好友列表:

{
  "data": [
    {
      "name": "aaa", 
      "id": "111"
    }, 
    {
      "name": "bbb", 
      "id": "222"
    }, 
    {
      "name": "ccc", 
      "id": "333"
    },
    ...
  ]
}

假设您要标记第一个人,您可以这样获取 ID:

$id = $taggable['data'][0]->id;

这将设置$id111.

然后,您可以调用 API 来标记照片,如下所示:

// set tags object (user_id, and position)
$tags = array( array( 'tag_uid' => $id, 'x' => 0, 'y' => 0 ) );

// call api, with json_encoded $tags
$tag = (new FacebookRequest( $session, 'POST', '/{photo_id}/tags', array( 'tags' => json_encode( $tags ) ) ))->execute()->getGraphObject()->asArray();

// output result
echo '<pre>' . print_r( $tag, 1 ) . '</pre>';
于 2014-07-30T11:35:56.007 回答