iOS Facebookgraphics请求多个图片大小

我正在使用Facebook的graphicsAPI,并试图获得用户的当前个人资料图片的两个不同的图片大小。 我想要一个图片的大小是250×250,另一个图片我想要的大小是1080×1080。 这是我现在的代码:

let params = ["fields": "first_name, last_name, email, picture.width(1080).height(1080)"] let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params) graphRequest.startWithCompletionHandler { (connection, result, error) in if error != nil { print(error) } } 

这将URL返回到一个大小为1080×1080的图片,并可以工作。 现在,如果我更改参数添加一个大小为250×250的图片的请求:

 let params = ["fields": "first_name, last_name, email, picture.width(250).height(250), picture.width(1080).height(1080)"] 

我得到这个错误基本上说我不能多次使用现场picture

 Syntax error "Field picture specified more than once. This is only possible before version 2.1" at character 94: first_name, last_name, email, picture.width(250).height(250), picture.width(1080).height(1080) 

这是否意味着唯一的方法来完成我想要的是批量请求 ? 如果是这样的话,是否有一个函数,一旦这两个批处理请求已完成被调用?

还有另外一种更好的方式,只用一个非批处理请求,通过使用字段别名来处理,最近我遇到同样的问题时遇到了这个问题。

在OP的情况下,fields参数将被设置为:

 first_name, last_name, email, picture.width(250).height(250).as(picture_small), picture.width(1080).height(1080).as(picture_large) 

然后,响应将包括两个名为picture_small和picture_large的字段,其中包含相应的图片数据。 例如:

 { "first_name": "Mark", "last_name": "Zuckerberg", "picture_small": { "data": { "height": 320, "is_silhouette": false, "url": "https://scontent.xx.fbcdn.net/hprofile-xtl1/v/t1.0-1/p320x320/12208495_10102454385528521_4749095086285673716_n.jpg?oh=e14ffdec03ceb6f30da80d1c4c5c4c02&oe=57254837", "width": 320 } }, "picture_large": { "data": { "height": 547, "is_silhouette": false, "url": "https://scontent.xx.fbcdn.net/hprofile-xtl1/v/t1.0-1/12208495_10102454385528521_4749095086285673716_n.jpg?oh=b008ae35daeea9b0d9babbee9d701a34&oe=572336EC", "width": 547 } }, "id": "4" } 

这工作对我来说,获得大尺寸的图像。 检查以下查询。 NSString * graphPath = [NSString stringWithFormat:@"%@?fields=photos.fields(id,link,source)", albumID];

你有两个解决scheme:

无聊的一个是提出两个要求。 而更好的解决方法是提出批量请求:

这是我的个人资料的cURL批量请求,它的工作原理:

curl -XPOST“ https://graph.facebook.com/v2.4 ”-d“access_token = put_your_access_token_here”-i -d“batch = [{”method“:”GET“,”relative_url“:”me?fields = first_name,last_name,picture.width(250).height(250)“},{”method“:”GET“,”relative_url“:”me?fields = first_name,last_name,picture.width(1080).height 1080)“}]'-i

你只需要把你的访问令牌。