iOS Facebook Graph请求多张图片大小 [英] iOS Facebook Graph Request multiple picture sizes

查看:177
本文介绍了iOS Facebook Graph请求多张图片大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook的图形API,并尝试获取用户当前个人资料图片的两种不同的图片大小。一张照片我想要大小为250x250,另一张图片我想要的尺寸为1080x1080。这是我现在的代码:

I'm using Facebook's graph API and am trying to get two different picture sizes of a user's current profile picture. One picture I would like to be size 250x250, and the other picture I would like be size 1080x1080. Here is my current code:

    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返回到大小为1080x1080的图片并可以工作。现在,如果我更改参数以添加一个大小为250x250的图片的请求:

This returns the URL to a picture of size 1080x1080 and works. Now if I change the params to add a request for a picture of size 250x250:

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

我得到这个错误基本上说我不能使用字段图片不止一次:

I get this error basically saying I can't use the field picture more than once:

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)

实现我想要的方法是制作批次请求?如果是这样,那么这两个批次请求是否完成都会被调用?

Does this mean the only way to accomplish what I want is to make a batch request? And if that's the case, is there a function that gets called once both batch requests have completed?

推荐答案

还有另一个(更好)通过使用字段别名,当我遇到同样的问题时,我最近遇到了。

There's another (better) way of doing this with just a single, non-batch request by using field aliasing, which I came across recently when I had the same issue.

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

In the OP's case the fields parameter would be set to:

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包含相应的图片数据。例如:

The response will then include two fields named picture_small and picture_large containing the respective picture data. E.g:

{
  "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"
}

这篇关于iOS Facebook Graph请求多张图片大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆