【问题标题】:Saving FB Img with Parse使用 Parse 保存 FB Img
【发布时间】:2016-09-17 17:49:29
【问题描述】:

我正在尝试保存一些从 Facebook 提取的当前用户信息并将其保存到我的解析数据库中。我已成功保存名称,但保存照片时遇到很多问题。这是我的代码:

 FBSDKGraphRequest(graphPath: "me",
                        parameters: ["fields": "id, name,friends, first_name, last_name, picture.type(large), email, gender,taggable_friends"])
                        .startWithCompletionHandler({ (connection, result, error) -> Void in

                    print(String(result["picture"]))
                    PFUser.currentUser()!["name"] = String(result["name"])      

                    let imageData = UIImagePNGRepresentation(result["picture"])
                    let imageFile = PFFile(name:"image.png", data:imageData)

                    PFUser.currentUser()?["imageFile"] = imageFile
                    PFUser.currentUser()?.saveInBackground()
                    })

任何帮助将不胜感激。

【问题讨论】:

  • 如果您只想保存一次图像(用户在 Facebook 中更改图像时不刷新),请按照 JVS 回答。如果您希望每次用户在 Facebook 上更改图像时都会更改图像,您可以将用户 Facebook ID 保存在特定列中,然后在客户端构造获取图像的 URL。

标签: ios swift xcode facebook parse-platform


【解决方案1】:

这是我在完成处理程序中的做法:

let userId:String = result.objectForKey("id") as! String
let facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "/picture?type=large"
let url = String(facebookProfilePictureUrl)

现在使用URL,您可以执行以下操作:

if let fbpicURL = NSURL(string: facebookProfilePictureUrl) {

   if let data = NSData(contentsOfURL: fbpicURL) {

      let imageFile:PFFile = PFFile(data: data)!


      PFUser.currentUser()?["imageFile"] = imageFile

      PFUser.currentUser()?.saveInBackground()
    }
}

编辑: 我不在我的 graphPath 中使用图像。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多