Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

Swift 5.1. External URL ( that is a facebook profile picture ) to save in Firebase storage

I got the facebook result using "FBSDKLoginKit.GraphRequest" it returns a dictionary named "result" that has the username, email and profile picture. I already got the Firebase Firestore to work, but the URL for the Facebook profile picture is not being saved to Firebase storage. ** If the URL is printed in the console, it works if I copy and paste it in a browser. This is my code:

// facebook GraphRequest and result
     let facebookRequest = FBSDKLoginKit.GraphRequest(graphPath: "me", parameters: ["fields": 
     "email, name, picture.type(large)"], tokenString: token, version: nil, httpMethod: .get)
        facebookRequest.start { [weak self] (_, result, error) in
            guard let strongSelf = self else {return}
            guard let result = result as? [String : Any], error == nil else {
                return
            }

            guard let username = result["name"] as? String, let userEmail = result["email"] as? 
     String, let fbPicData = result["picture"] as? [String:Any], let data = fbPicData["data"] 
     as? [String:Any], let fbAvatar = data["url"] as? String  else {
                return
            }


// Firebase STORAGE and URL ( fbAvatar is the constant that has the url needed)
// The code below this line is where this issue lays.
let storageRef = Storage.storage().reference(forURL: "STORAGE NAME")
                    let storageProfileRef = storageRef.child("STORAGE NAME")
                    guard let url = URL(string: fbAvatar) else {
                        return
     }
                    print("Downloading url image from facebook")
                    URLSession.shared.dataTask(with: url, completionHandler: {data , _ , _ in
                        guard let data = data else {return}
                        storageProfileRef.putData(data)
                        if error != nil {
                            return
                        }
                    })
question from:https://stackoverflow.com/questions/66048993/swift-5-1-external-url-that-is-a-facebook-profile-picture-to-save-in-fireba

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...