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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…