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 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效