ios - 无法获取 Facebook Graph API 用户照片边缘的单个大尺寸

标签 ios swift facebook-graph-api swift4

我在 iOS 应用程序中使用 facebook sdk 进行登录和 user_photos 目的。

登录完成,在权限中我添加了 user_photos readPermissions

但是当我尝试使用 graphPath: me/photos with fields 获取用户照片时参数-id,picture ,仅返回最小的图像尺寸。我尝试过使用 picture.type(large)picture.width(640) ,但没有任何作用。

我尝试使用images fields 的参数,它返回照片节点的所有尺寸。

我什至尝试使用边缘 <OBJECT_ID>/picturefields参数picture ,但它给出了 facebook sdk error(error code 6) .

如何将只有单个照片链接的用户照片变成大尺寸?

我使用的是最新版本的 SDK。

最佳答案

Swift - 试试这个

@IBAction func facebookLoginButtonTapped(_ sender: UIButton) {
            let fbLoginManager: FBSDKLoginManager = FBSDKLoginManager()
            fbLoginManager.logIn(withReadPermissions: ["email", "pages_show_list"], from: self) { (result, error) in
                if (error == nil){
                    let fbLoginResult: FBSDKLoginManagerLoginResult = result!
                    if fbLoginResult.grantedPermissions != nil {
                        if(fbLoginResult.grantedPermissions.contains("email")){
                            self.facebookLogin()
                        }
                    }
                }
            }
        }
    }
<小时/>
    func facebookLogin() {
        if((FBSDKAccessToken.current()) != nil) {
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id, name, first_name, last_name, picture.type(large), email "]).start(completionHandler: { (connection, result, error) in
                if result == nil {
                }
                else{
                    self.userResults = result as! [String : AnyObject]
                    self.email = (self.userResults["email"] as? String) ?? ""
                    if (self.email != "") {
                        let url = URL(string: "http://graph.facebook.com/\(YOURE FACEBOOK ID)/picture?type=large")!
                        let session = URLSession(configuration: .default)
                        let downloadPicTask = session.dataTask(with: url) { (data, response, error) in
                            // The download has finished.
                            if let e = error {
                                print("Error downloading cat picture: \(e)")
                            } else {
                                if let res = response as? HTTPURLResponse {
                                    print("Downloaded cat picture with response code \(res.statusCode)")
                                    if let imageData = data {
                                        let image: UIImage = UIImage(data: imageData)!
                                    } else {
                                        print("Couldn't get image: Image is nil")
                                    }
                                } else {
                                    print("Couldn't get response code for some reason")
                                }
                            }
                        }
                        downloadPicTask.resume()
                    }
                    else{
                        Utility.showAlert("Login Faild", message: error?.localizedDescription, viewController: self)
                    }
                }
            })
        }
    }

关于ios - 无法获取 Facebook Graph API 用户照片边缘的单个大尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50559653/

相关文章:

ios - 渐变颜色在非英语语言的 UILabel 中被截断

ios - 无法使用 Alamofire 通过服务器上传音频文件

ios - swift : Does hiding an animating view still affect memory/performance?

javascript - 使用 Facebook API 发布到页面时添加定位

facebook - 存储 Facebook API 数据

facebook-graph-api - 不明白 "(#4) User request limit reached"

ios - 如何在 Swift 中更新 Parse 用户信息?

ios - 如何从 AFNetworking ios 中的 block 中提取数据?

objective-c - ARC如何判断是使用retain还是copy呢?

swift - Swift 中的高精度 float