douwei2713 2014-07-29 14:59
浏览 41
已采纳

使用Facebook api获取好友ID以标记上传的照片

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

  • 写回答

1条回答 默认 最新

  • doushang2023 2014-07-30 11:35
    关注

    Once you've made the API call, you'll get a list of friends like:

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

    Assuming you want to tag the first person, you can get the ID as so:

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

    This will set $id as 111.

    You can then call the API to tag the Photo, as follows:

    // 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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?