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条)

报告相同问题?