获取使用Facebook API的朋友ID来标记上传的照片
-
21-12-2019 - |
题
我有以下代码
$taggable = (new FacebookRequest(
$session,
'GET',
'/me/friends'
))->execute()->getGraphObject()->asArray();
echo '<pre>' . print_r( $taggable, 1) . '</pre>';
.
我正在尝试获取也使用该应用程序的朋友列表的ID,以便用户可以使用这些朋友标记照片。现在代码打印了也使用应用程序的朋友,他们的名称和ID。我想将朋友的ID获取到“标签”的参数中,但GetProperty('id')不起作用并给我一个错误。我是Facebook API的新手,所以我不熟悉语法。
如何将朋友的ID放入:
'tags' => '[{\'tag_uid\': \'testing\'}]',
.
感谢
解决方案
一旦您完成了API调用,您将获得类似的朋友列表:
{
"data": [
{
"name": "aaa",
"id": "111"
},
{
"name": "bbb",
"id": "222"
},
{
"name": "ccc",
"id": "333"
},
...
]
}
.
假设您要标记第一个人,您可以获得id:
$id = $taggable['data'][0]->id;
.
这将设置生成的$id
作为111
。
然后您可以调用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>';
. 不隶属于 StackOverflow