dowy77780 2014-11-24 12:00
浏览 53
已采纳

使用Facebook PHP SDK在单个请求中检索多个字段

Upon user registration I fetch the users data (name, birthday, location, etc) and also the users profile image.

Currently, I would be able to do this: /me?fields=picture,name, but the picture returned is too low resolution, so I'd like to fetch the picture with the height parameter (as described here).

My only option, as I see it, is to part it up in two requests, which seems inefficient:

  • Get user data me/?fields=name
  • Get user picture me/picture?height=500&redirect=false

Would there be a way to merge this into ONE request?

  • 写回答

2条回答 默认 最新

  • dongqian6484 2014-11-24 13:13
    关注

    Use field expansion, just one API call:

    /me?fields=name,picture.width(500).height(500),birthday
    

    API Explorer test: https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Dname%2Cpicture.width%28500%29.height%28500%29&version=v2.2

    More information about field expansion: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#fieldexpansion


    Batch Requests would be another solution, although not a very good one in that case because they are a lot more complicated (more code, more things to consider) and they don´t count as one call:

    each call within the batch is counted separately for the purposes of calculating API call limits and resource limits

    ...meaning, they are only faster than 2 separate calls (as fast as the slowest call in the batch), but field expansion is really just 1 call. Batch Requests are for "potentially unrelated Graph API calls".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答