Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook graph api 使用Facebook API、Firebase和Swift获取100x100个人资料图片_Facebook Graph Api_Firebase_Swift3 - Fatal编程技术网

Facebook graph api 使用Facebook API、Firebase和Swift获取100x100个人资料图片

Facebook graph api 使用Facebook API、Firebase和Swift获取100x100个人资料图片,facebook-graph-api,firebase,swift3,Facebook Graph Api,Firebase,Swift3,我的项目使用以下代码获取中等大小的个人资料图片的URL字符串: let downloadMediumPicTask = session.dataTask(with: mediumProfPictureURL) { (data, response, error) in // The download has finished. if let e2 = error { print("Error downloadin

我的项目使用以下代码获取中等大小的个人资料图片的URL字符串:

 let downloadMediumPicTask = session.dataTask(with:       mediumProfPictureURL) { (data, response, error)
        in
        // The download has finished.
        if let e2 = error {
            print("Error downloading profile picture: \(e2)")
        } else {
            if let res2 = response as? HTTPURLResponse {
                print("Downloaded medium profile picture with response code \(res2.statusCode)")
                if let imageData2 = data {
                    mediumProfilePictureUIImageFile = UIImage(data: imageData2)!
                    print("mediumProfilePictureUIImageFile has now been defined as: \(mediumProfilePictureUIImageFile).")
                } else {
                    print("Couldn't get image: Image is nil")
                }
            } else {
                print("Couldn't get response code for some reason")
            }
        }
    }
    downloadMediumPicTask.resume()
它在这里崩溃,给出403响应代码。所引用的URL是来自Facebook的过期签名URL。Firebase没有调整以获得新的适当URL,而我是从Firebase获得URL的。我想不出如何直接获得它,如下所示:

   func getUrlOfMediumProfilePic(){

    if (FBSDKAccessToken.current() != nil) {
        let graphPathPart2 = "me/picture"
        let paramsPart2 = ["type":"medium", "redirect":"false"]
        let completionHandlerPart2 = { (connection: FBSDKGraphRequestConnection?, result: Any?, error: Error?) in

            if let error = error {
                print("Medium picture graph call contained an error: \(error.localizedDescription)")
                return
            } else {
                guard connection != nil else {
                    print("getURLOfLargeProfilePic() function aborted bc connection failed.")
                    return
                }
                let results = result! as! NSDictionary
                let dataDict = results["data"] as! NSDictionary
                stringOfMediumProfilePicURLaka100x100 = dataDict["url"] as! String
                print("medium picture graph call results define stringOfMediumProfilePicURLaka100x100 as: \(stringOfMediumProfilePicURLaka100x100)")
            }
        }
        let graphRequest = FBSDKGraphRequest(graphPath: graphPathPart2, parameters: paramsPart2)!
        graphRequest.start(completionHandler: completionHandlerPart2)
    }else{
        print("User not logged in when getURLOfMediumProfilePic() function was run.")
        return
    }
}
此代码产生代码8的错误。

您是否尝试过此操作:

https://graph.facebook.com/{id}/picture?width=100&height=100
我不懂斯威夫特,所以我无法帮助你理解语法。我认为您可以对url发出http请求并获取图像。 希望这有帮助:)