Not Getting Own Birthdate from Facebook - ios

I have done lots of R&D to getting private birthday from facebook, but not able to get private birthday.
I have given birthday permission in code. Also tried to delete app from user's account but no luck.
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, birthday, name, first_name, last_name, picture.type(large), email, gender"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
Print("Success")
}else{
Print("Failed")
}
})
}else{
Print("Device token is Nil")
}
Please Help me out where is my mistake.

To access birthdate from facebook, You need to request for
user_birthday permission and submit you app for facebook review. If
facebook will approve this permission, then you can get birthdate.
meanwhile you can test using the account in which you have registered
your app.
Go through
https://developers.facebook.com/docs/facebook-login/permissions#reference-user_birthday

Related

Get Facebook Friends Possible 2020

All the answers that was available are too old tried different ways but not able to get any information related to facebook logged in user friends.
let loginManager = LoginManager()
loginManager.logIn(permissions: ["public_profile", "email", "user_friends"], from: loginScreen) { (result, error) in
if (result?.token != nil) {
self.didLoginWithFacebook()
}
}
the above set "user_friends" permission is not getting asked from the user and also not coming back in granted or denied permission.
And also using
let graphRequest = GraphRequest(graphPath:"me/friends", parameters: ["fields":"id,email,last_name,first_name,picture"], tokenString: accessToken.tokenString, version: nil, httpMethod: .get)
graphRequest.start { (connection, result, error) in
guard let result = result as? [String:String] else{
print("Facebook request user error")
return
}
}
returning empty data fields
I want to know is it even possible to get friends or not ?
Even we don't get friends after asking the user for permission ?
Getting error when trying to login with admin user
According to
https://developers.facebook.com/docs/graph-api/reference/user/friends/
This api returns only
Represents a collection of Users who are friends of the app User. Only
friends who have installed the app and who have granted the app the
user_friends permission will be included.
So, if You don't have any friends who also installed your app and granted friends permission -> response still be empty
Try with an app admin, regular users will not be able to use the permission if it is not approved by Facebook yet
There is a missing apostrophe in your code, right after user_friends:
permissions: ["public_profile", "email","user_friends"...

Facebook Graph API mutual friends images

I'm able to retrieve users' mutual friends using context.fields(mutual_friends)but I need to display images of the friends. However, I'm only getting back the friends id and name only. Is it possible to retrieve their images in the same call?
if((FBSDKAccessToken.current()) != nil){
FBSDKGraphRequest(graphPath: "/\(userID)", parameters: ["fields": "context.fields(mutual_friends)"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
print("//////Mutual friends")
print(result!)
} else {
print(error!.localizedDescription)
}
})
}
You can get the image with using this API
https://graph.facebook.com/(friendFacebookId)/picture?type=large
For more info check this

Facebook Graph API - Getting mutual likes

I have an issue when getting mutual likes with Facebook Graph API. The context is the following:
userA is the requester from an iOS application
userA and userB have granted "user_likes" permission both from the iOS app
userA and userB are not Facebook friends
My app Swift code for this part is the following:
self.FBLoginButton.readPermissions = ["public_profile", "email", "user_friends", "user_birthday", "user_about_me", "user_likes"]
...
...
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: userBFBid, parameters: ["fields": "context.fields(mutual_likes).limit(10)"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil) {
print("Error: \(error)")
} else {
print("res: \(result)")
}
})
The result is the following:
res: {
context = {
id = dXNlcl9jb250ZAXh0OgGQg20zLjrZAswOnuX6*******;
"mutual_likes" = {
data = (
);
summary = {
"total_count" = 0;
};
};
};
id = 101532998**********;
}
As you can see, the mutual likes are not returned.
I made the same request with userA and userC which are Facebook friends, and that works correctly, all their mutual likes are returned.
Again: userA, userB and userC have the app installed and granted the user_likes permission.
Any idea to fix it and to get mutual_likes with two users which are not Facebook friends?
I finally found the issue.
First of all: user likes must be visible by public in FB user account privacy configuration to be accessible by the API even if the user_likes permission is granted.
Source: Facebook graph api empty data when getting user likes
Secondly, if the users are not friends on Facebook, the request must also include the parameter appsecret_proof (https://developers.facebook.com/docs/graph-api/securing-requests). So the request must be performed from your server and not from your app for safety reason. Source: https://developers.facebook.com/bugs/101463963524794/
Hope that helps someone one day!

Facebook Login doesn't fetching all User's profile information in swift

In my app I implemented FacebookLogin accessing permissions:
let facebookReadPermissions = ["public_profile", "email", "user_friends"]
Once all permissions granted, I am calling graph API for fetching user's profile info using:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
It is returning just two values: { id = 86160953055XXXX; name = "Devendranath Reddy"; }
I want Address, email, phone, first and last names also.
What is wrong here.
I even enabled for live access in developer.apple.com -> MyApp -> Settings
Please help me out.
Thanks in advance.
try this out, you need to set the parameters value:
so for Swift it would be this:
parameters:#{#"fields": #"id, name"}
In swift it would be something similar
something like this:
let params = ["fields": "email, friends"]
so:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)
Add whatever fields you want to add, like "first_name" "last_name" etc, etc.
let params = ["fields": "email, first_name, gender, last_name, location"]
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)
graphRequest.startWithCompletionHandler(
{
(connection, result, error) -> Void in
if ((error) != nil)
{
// Failure code goes here.
}
else
{
// Success code goes here
println("User Name is: \(userName)")
println("User Email is: \(userMail)")
println("Gender is: \(gender)")
}
})
This request won't grab all the information until your app is reviewed by Facebook's app review. It will only give you access to the public profile info, regardless of what permissions the user accepts.

Trouble retrieving list of facebook friends from json data in swift

I am using FBSDK in my Swift iOS application and currently I am trying to retrieve the list of friends who also use my app. I have two-three people who should show up but whenever I search the graphrequest result for friends it returns nil..
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result:AnyObject!, error) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
//get Facebook ID
let faceBookID: NSString = result.valueForKey("id") as NSString
//get username
let userName : NSString = result.valueForKey("name") as NSString
//get facebook friends who use app
let friendlist: AnyObject = result.valueForKey("friends") as AnyObject
}
I have the "email", "user_friends", and "public_profile" permissions which should be enough to retrieve this information. Any Ideas on what I am doing wrong?? this is doing my head in as my friend doing an android version has successfully got his working..
My problem here was that I never Actually requested for the list of friends in my facebook graph request...
after replacing FBSDKGraphRequest(graphPath: "me", parameters: nil)
with FBSDKGraphRequest(graphPath: "me?fields=id,name,friends", parameters: nil)
I was able to retrieve the list of friends because the response actually contained information for this. A very trivial mistake on my part.
In v2.0 of the Graph API, you must request the user_friends permission
from each user. user_friends is no longer included by default in every
login. Each user must grant the user_friends permission in order to
appear in the response to /me/friends.
see here : https://developers.facebook.com/bugs/1502515636638396/

Resources