FBRequest:为什么不允许非文本mime类型响应?(iOS SDK)

Chr*_*ris 5 image facebook-ios-sdk

使用Facebook iOS SDK,假设我对用户的个人资料图片执行图形请求:

[FBRequest requestForGraphPath:@"me/picture"]
Run Code Online (Sandbox Code Playgroud)

我会收到这个错误:

Response is a non-text MIME type; endpoints that return images and other binary data should be fetched using `NSURLRequest` and `NSURLConnection`.
Run Code Online (Sandbox Code Playgroud)

这背后的原因是什么?手动编写请求只需要一分钟,但为什么这个常见任务不包含在Facebook iOS SDK中,或者我错过了什么?

通过Github上的Facebook iOS SDK repo,我们可以看到FBRequestConnection.m:

if (!error && [response.MIMEType hasPrefix:@"image"]) {
        error = [self errorWithCode:FBErrorNonTextMimeTypeReturned
                         statusCode:0
                 parsedJSONResponse:nil
                         innerError:nil
                            message:@"Response is a non-text MIME type; endpoints that return images and other "
                                    @"binary data should be fetched using NSURLRequest and NSURLConnection"];
    }
Run Code Online (Sandbox Code Playgroud)

如果我正确理解这一点,FBRequestConnection得到我想要的反应(即个人资料图片)然后告诉我我不能拥有它.多么可爱啊.为什么要首先提出请求?

对此有何评论?

Eva*_*Lin 5

对于大图片

me?fields=picture.type(large)

请参阅Facebook Graph API更改:图片类型(大小)不再有效?


Swi*_*ude 2

解决方案是要求特定字段而不是图片(可在此处找到:Facebook Graph API will not Give me picture data

所以使用

[FBRequest requestForGraphPath:@"me?fields=picture"]
Run Code Online (Sandbox Code Playgroud)

那应该有效