backendless easy facebook login: fetching first name - ios

I'm trying to login to facebook using backendless easyLogin* method in Swift and to fetch user's facebook name to display further. I'm able to login successfully but can't get the name.
The code is as the following ("first_name" is facebooks graph field to map, "displayName" is backendless custom user field):
let backendless = Backendless.sharedInstance();
backendless.userService.easyLoginWithFacebookFieldsMapping(
["email":"email", "first_name":"displayName"], permissions: ["email", "public_profile"],
response: {(result : NSNumber!) -> () in
print ("Result: \(result)")
},
error: { (fault : Fault!) -> () in
print("Server reported an error: \(fault)")
})
What am I missing here?

Not sure what was the exact problem but the following worked for me:
I've removed previously created facebook user from backendless user table
Tried to login using the following code snippet:
func easyFacebookLogin() {
let fieldsMapping = [
"name" : "name",
"first_name": "first_name",
"last_name" : "last_name",
"email": "email"]
backendless.userService.easyLoginWithFacebookFieldsMapping(
fieldsMapping,
permissions: ["email"],
response: {(result : NSNumber!) -> () in
print ("Result: \(result)")
},
error: { (fault : Fault!) -> () in
print("Server reported an error: \(fault)")
})
}
Everything worked as expected - name was fetched and mapped

Related

LISDKErrorAPIDomain error 403

I am trying to share a url, image and a text to linkedin through my app. But it shows an error as
The operation couldn’t be completed. (LISDKErrorAPIDomain error 403.)
My code is
func didLinkedinBtnPressed(cellObject: MyModel) {
let tmp = ["comment": cellObject.strSocialText!,
"content": ["title":"AppName", "description":cellObject.strSocialText!,"submitted-url":cellObject.strWebSite!,"submitted-image-url":cellObject.strImageUrl!],"visibility": ["code": "anyone"]] as [String : Any]
print("PostDtaa = \(tmp)")
let postData = try? JSONSerialization.data(withJSONObject: tmp, options: .prettyPrinted)
let url = NSString(string:"https://api.linkedin.com/v1/people/~/shares?format=json")
let permissions: [AnyObject] = [LISDK_BASIC_PROFILE_PERMISSION as AnyObject, LISDK_EMAILADDRESS_PERMISSION as AnyObject,LISDK_W_SHARE_PERMISSION as AnyObject]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (success) -> () in
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().postRequest(url as String, body: postData, success: { (_ response) in
print(response ?? "")
self.simpleAlert(titleOfAlert: "Success", messageOfAlert: "Shared Successfully")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
}, error: { (_errorRes) in
print(_errorRes?.localizedDescription ?? "No Error!!!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
}, errorBlock: { (error) -> () in
print("%s", "error called!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
Why am i getting a 403 error here?
I experimented a similar issue in the past it was related to the w_share permission
from the linkedin doc
Required permission: w_share
Whether set as a default permission in your app settings or requested
specifically via the scope argument during your authentication
process, you will need to request the w_share member permission in
order for your application to successfully make the API call to share
content.
w_share is disabled by default so it has to be explicitly enabled
NOTE: the token could be cached by app so in order to be sure that a new token (with the updated permissions) is used, I strongly suggest you to uninstall everything from your mobile device and re-install it again.

How to get user's feed from Firebase?

I have an iOS app that has a feed system basically like Facebook (With Firebase as server) and I'm trying to get the latest Posts from all the people that the user is following, but I can't find a way to loop through all data. Can I get a hand?
So this is more or less how my database is:
{
"Posts" : {
"Zlv1rX3p74R4G8DUvvBOcCiThcx1" : {
"-KacGJ-ps8FgCYvSag-D" : {
"latitud" : "37.33233141",
"longitud" : "-122.0312186",
"text" : "Party at my house",
"timestamp" : "1484586828.01879",
"ubicacionN" : "Apple Inc."
}
}
},
"following" : {
"Zlv1rX3p74R4G8DUvvBOcCiThcx1" : {
"Bdxaooy1HieFajZfZL8OeDFS1Q73" : {
"Uid" : "Bdxaooy1HieFajZfZL8OeDFS1Q73",
"handle" : "dnla",
"name" : "Daniela",
"profile_pic" : "https://firebasestorage.googleapis..."
}
}
}
}
I got the posts in one part and the list of following in another part (I'll add a complete pic of my DB at the end)
I'm not really familiar with NSDictionary so that's why I'm running into troubles, so I started doing this:
self.databaseRef.child("following").child(self.loggedInUser!.uid).observe(.childAdded, with: { (snapshot) in
//Getting the list of following
let snapshot = snapshot.value as? NSDictionary
self.following.append(snapshot)
}) { (error) in
print(error.localizedDescription)
}
for item in self.following {
Some code to get every user that the main user is following latests posts
}
but I'm hitting my head right now, some help please.
Picture explanation: Jalas = Posts

How to retrieve Email from Facebook SDK

Note: please do not close as duplicate, I went through almost every existing thread here on Stackoverflow, but my problem is still not solved.
This is my Swift 3 function with the latest Facebook SDK:
let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"email,name"], tokenString: token?.tokenString, version: nil, httpMethod: "GET")
_ = req?.start(completionHandler: { (connection, result, error : Error?) -> Void in
if(error == nil) {
print("result \(result)")
} else {
print("error \(error!)")
}
})
Result:
result Optional({
id = 102080884567XXXXX;
name = "David Seek";
})
Email permission is approved:
Also the App is in live mode:
I have checked the reference guide, but I can't find my mistake.
My problem is, that I'm saving the facebookID as Email adress into my backend and I'm trying to figure out why... Therefore I have tried the provided code on top, but I'm not receiving the Email.
let result = FBSDKApplicationDelegate.sharedInstance().application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
if result {
let token = FBSDKAccessToken.current()
let fieldsMapping = [
"id" : "facebookId",
"name" : "name",
"birthday": "birthday",
"first_name": "fb_first_name",
"last_name" : "fb_last_name",
"gender": "gender",
"email": "email"
]
backendless?.userService.login(withFacebookSDK: token, fieldsMapping: fieldsMapping, response: { (user: BackendlessUser?) in
}, error: { (fault: Fault?) -> Void in
print("Server reported an error: \(fault)")
})
}
I'm receiving every information, but the Email...
What am I missing? Help is very appreciated.
Email permission is granted:
That is not what that screenshot shows. It shows that it is approved, meaning your app can ask users for it. But it still has to ask.
Make sure that has happend successfully - either by debugging the access token, or via an API call to /me/permissions
You need to ask the user for permission during login.

removing trimming special characters

I've been trying to trim and remove characters from:
{
"data":
{
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/13254063_1039990606071446_7680951628744860479_n.jpg?oh=e5088fb1a981041f60c9abde6762d892&oe=57C12344"
}
}
and convert it at something like:
https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/13254063_1039990606071446_7680951628744860479_n.jpg?oh=e5088fb1a981041f60c9abde6762d892&oe=57C12344
Here is my code :
let dataStore = backend.persistenceService.of(Users.ofClass())
dataStore.find(
{ ( users : BackendlessCollection!) -> () in
print("Users have been fetched (ASYNC): \(users)")
let page = users.getCurrentPage()
for userx in page {
print(userx.picture)
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error (ASYNC): \(fault)")
}
)
Seems you are reading from response.
The URL you want and response URL are both same.
So no need to trim it, you can get the URL from the response directly by using valueForKey or objectForKey method.
var URL: String = data.valueForKey("URL") as? String

Changing User Email and Password with Swift and Firebase

Here's my edit button for an iOS application with swift and firebase.
var ref = Firebase(url:"https://·············.firebaseio.com")
#IBAction func Done(sender: AnyObject) {
ref.changeEmailForUser("users/\(self.ref.authData.uid)/email",
password: "users/\(self.ref.authData.uid)/provider", toNewEmail: EmailTextField.text)
{ (ErrorType) -> Void in
if ErrorType != nil {
print("There was an error processing the request")
} else {
print("Email changed successfully")
}
}
ref.changePasswordForUser("users/\(self.ref.authData.uid)/email",
fromOld: "users/\(self.ref.authData.uid)/provider", toNew: PasswordTextField.text)
{ (ErrorType) -> Void in
if ErrorType != nil {
print("There was an error processing the request")
} else {
print("Password changed successfully")
}
}
ref.childByAppendingPath("users").childByAppendingPath(self.ref.authData.uid).updateChildValues(["name":self.NameTextField.text!,"about":self.TextView.text!,"Picker":self.PickerVar])
}
When the user clicks the done button I want to update all of his information in the firebase.
Email, Password, Name, etc.
All of the information updated when I click the done button, except for email and password!
It's says there was an error processing the request:
as the picture here
I don't know where 's the error! Did I use the changeEmailForUser and changePasswordForUser functions in a wrong way?
Here's the JSON tree:
{
"users" : {
"7b595e99-b20d-4961-bcf0-6c46956a0cbe" : {
"Picker" : "Student",
"about" : "Hey, I'm Here",
"email" : "mariah#gmail.com",
"name" : "Mariah Khayat",
"provider" : "password"
},
"7eb23db6-6b56-4225-9306-22ed0b935b52" : {
"Picker" : "Teacher",
"about" : "Hi",
"email" : "mmm#gmail.com",
"name" : "Memo",
"provider" : "password"
}
}
}
Accarding to Firebase API making some confusion. after i seen the API https://www.firebase.com/docs/ios/api/#firebase_changeEmailForUserpasswordtoNewEmailwithCompletionBlock There is clearly said:
So for the update Email For user this is not a part a update profile. So as per following you can change your email address:
ref.changeEmailForUser("OldEmailthatYouuserForLogin", password: "correctpassword",
toNewEmail: "newEmail", withCompletionBlock: { error in
if error != nil {
print("There was an error processing the request")
// There was an error processing the request
} else {
print("Email changed successfully")
// Email changed successfully
}
})
// Dont use edited email for the old email and edited password for the password make sure you are using your actually email and password
Mariah,
The problem is your entered email and password details. You are showing the path for your email and password but instead you should enter what calls them such as.
instead of ""users/(self.ref.authData.uid)/email" you should provide it as ref.authData.providerData["email"]as? NSString as? String
for password you need to edit your Firebase rules so user can have access to his own password.

Resources