Facebook all_mutual_friends not working - ios

I'm building an iOS app that connects to Facebook's all_mutual_friends API
https://developers.facebook.com/docs/graph-api/reference/user-context/all_mutual_friends/
The app has been reviewed and approved to connect to this API.
When I make the graph call per the documentation:
let params = ["fields":"context.fields(all_mutual_friends.fields(picture.width(500).height(200)))"]
FBSDKGraphRequest(graphPath: "/\(facebookID)", parameters: params, HTTPMethod: "GET").startWithCompletionHandler { (connection, result, error) in
print("result: \(result)")
print("error: \(error)")
}
I get the following result:
result: {
context = {
id = dXNlcl9jb250ZAXh0OgGQ8qbGU5YUiZAKn8g4zuCb1LCMGj3PiCXfe7B72X5DoKkbMpHZA395xRT0iV8D84NQIZBCjJ3VRKC9uNUrMZCiwIeZBOSTRndZCQKi4pgiIgLoxI3xAZD;
};
id = 10208913134493418;
}
The above response is when we have a mutual friend who has the app installed.
Does anyone know how to get the list of mutual friends?
If I am Facebook friends with the person, I successfully receive a list of mutual friends making the same graph call. This is the response:
context = {
"all_mutual_friends" = {
data = (
{
"first_name" = Mary;
picture = {
data = {
height = 200;
"is_silhouette" = 0;
url = "https://...";
width = 200;
};
};
}, //... 24 more results
This is great because there is data, but it is limited to 25 mutual friends. Is there a way to increase the limit above 25?

According to the Facebook documentation you referred above :
The All Mutual Friends API must be called from your server to obtain the full list of mutual friends. Calling this API in JavaScript, Android, or iOS client code will omit some of the results.
This explains the limit you are facing. :)

Related

Get insights/page_fans for a Facebook page from Facebook's open graph

I'm trying to get the number of fans that a music artist has on their Facebook page, but it's not working. I've combed through the FBAPI docs as well as SO and still nothing. Here's my code:
func getHolychildInfo() {
//Make request
let newGraphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/holychildmusic/insights/page_fans", parameters: ["period" : "lifetime", "show_description_from_api_doc" : "true", "fields": "read_insights"], httpMethod: "GET")
newGraphRequest.start(completionHandler: { (connection, result, error) in
if ((error) != nil) {
print("Holychild error getting insights: \(error.debugDescription)")
} else {
print("\nHolychild insights result:\n\n\(result)")
}
})
}
Here's my result:
data = (
);
paging = {
next = "https://graph.facebook.com/v2.8/holychildmusic/insights/page_fans?access_token=EAAIB5k3aWEEBAHBD9lZC5AAzZAVV8K8CGBfqaxcrLdZA7oZB2Gdar8cQphXj4VciloZAnZBKp5ZA59BmGloSNz847nFqZCTVsYZCl9rrOk88OnfCnDwwADKnkOO5EUhGumEbW96riHplgfBLdnZAEYmB2Qz4ZAH1sWbuftmGKDqPft4l5QAHSZAimIyI6sOHaKWiurRK201Af6NQCXGliZBsZAUYosUHttkUbo4CQZD&fields=read_insights&format=json&include_headers=false&period=lifetime&sdk=ios&show_description_from_api_doc=true&since=1487457711&until=1487716911";
previous = "https://graph.facebook.com/v2.8/holychildmusic/insights/page_fans?access_token=EAAIB5k3aWEEBAHBD9lZC5AAzZAVV8K8CGBfqaxcrLdZA7oZB2Gdar8cQphXj4VciloZAnZBKp5ZA59BmGloSNz847nFqZCTVsYZCl9rrOk88OnfCnDwwADKnkOO5EUhGumEbW96riHplgfBLdnZAEYmB2Qz4ZAH1sWbuftmGKDqPft4l5QAHSZAimIyI6sOHaKWiurRK201Af6NQCXGliZBsZAUYosUHttkUbo4CQZD&fields=read_insights&format=json&include_headers=false&period=lifetime&sdk=ios&show_description_from_api_doc=true&since=1486939311&until=1487198511";
};
As you can see, there is nothing in the "data" part of the response. The "page_fans" insights metric is supposed to return a number - among other things - but instead returns nothing.
All insights metrics besides the two public ones (page_fans_country and page_storytellers_by_country) require admin access to the page (admin user or page access token with read_insights permission.)
But the fan_count field of the page object is public, so just request that:
https://developers.facebook.com/tools/explorer/?method=GET&path=holychildmusic%3Ffields%3Dfan_count&version=v2.8

Get game request ID / Access Facebook game request notification content

I am trying to send requests with data to Facebook friends in my app. The requests are successfully sent and I do get notifications. However the message on the notifications is not what I specify (the notification I get is xxxxx sent you a request. I specified Please help me with 5 lives). Also, I can't access any data of the request received.
This is how I'm sending the request:
func sendLifeRequest(index: Int) {
let content = FBSDKGameRequestContent()
content.message = "Please help me with 5 lives"
content.data = "5lives"
let id = facebookFriends[index].id as NSString
var to: [NSString] = [NSString]()
to.append(id)
content.recipients = to
FBSDKGameRequestDialog.show(with: content, delegate: self)
}
This is how I'm trying to get it in the other end:
FBSDKGraphRequest(graphPath: "https://graph.facebook.com/me/apprequests?access_token=" + FBSDKAccessToken.current().tokenString, parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
print(requestError) // prints nil
print(user)
})
print(user) prints:
Optional({
id = "https://graph.facebook.com/me/apprequests";
"og_object" = {
id = xxxxxxxxxxxxx;
type = website;
"updated_time" = "2016-10-19T05:32:20+0000";
};
share = {
"comment_count" = 0;
"share_count" = 0;
};
Update: I found out that if I copy the request ID and copy it for graph path it works. Does anyone knows how to get this ID from receivers end
func gameRequestDialog(_ gameRequestDialog: FBSDKGameRequestDialog!, didCompleteWithResults results: [AnyHashable : Any]!) {
print("request sent")
print(results) // copied ID from here
}
and pasted...
FBSDKGraphRequest(graphPath: THE ID HERE, parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
print(requestError) // prints nil
print(user)
})
now print user prints:
Optional({
application = {
category = Games;
id = xxxxxxxxxxxx;
link = "https://www.facebook.com/games/?app_id=1841299476156545";
name = "Crazy Traffic Saga";
};
"created_time" = "2016-10-24T21:25:34+0000";
data = 5lives;
from = {
id = xxxxxxxxxxxx;
name = "xxxxxxxxxxxxxx";
};
id = xxxxxxxxxxxx;
message = "Please help me with 5 lives";
})
The problem is I copied when I log in with the user sending and copied to the user receiving. I still can't just access it just by code from the receiver.
Facebook documentation on Game request says:
"In order to read all the requests for a recipient for you can query the graph as shown below using the recipient's USER ACCESS TOKEN. This will return a list of request ids for that user in the app.
GET https://graph.facebook.com/me/apprequests?access_token=[USER ACCESS TOKEN]"
But thats what I was doing at first...
I found it. the request should be "/me/apprequests"
so:
FBSDKGraphRequest(graphPath: "/me/apprequests", parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
})

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!

Retrieveing media liked by the user returns nothing

I'm trying to get the media liked by the logged in user. I do the authentication process and get an access token like this.
1312564049.dd97f3a.e9gw8d5516414d348c0b34f328e80fb1
I made sure to ask for public_content scope permission as well.
Then I call the /users/self/media/liked endpoint passing this token.
let urlString = "https://api.instagram.com/v1/users/self/media/liked"
let params = ["access_token": token]
Alamofire.request(.GET, urlString, parameters: params, encoding: .URL, headers: nil).responseJSON { response in
print(response.description)
}
But I get the following as the result.
{
data = (
);
meta = {
code = 200;
};
pagination = {
};
}
There are many photos liked by the user account I use. So I'm baffled why this returns empty. Is this because I'm in sandbox mode? Or something wrong with this endpoint? Because I checked /users/self and /users/self/media/recent and they both returned results.
Its because of the sanbox mode.
https://www.instagram.com/developer/sandbox/
Data is restricted to the 10 users and the 20 most recent media from each of those users

get all facebook contacts with swift

I'm trying to get all my facebook contacts. With this code managed to catch however I can not bring the phone information and email contacts. This is my code:
let params = ["fields": "first_name, last_name, name, email, picture, phone"]
let request = FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters: params);
request.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
if error == nil {
self.appDelegate.dismissHUD()
let resultdict = result as! NSDictionary
self.fbContact = resultdict.objectForKey("data") as! NSArray
print(self.fbContact)
self.loadData()
} else {
self.appDelegate.showError("Time Out")
}
it returns this dictionary:
(
{
"first_name" = xxxx;
id = "AaJRSpI-fYgIaPMaJCHEgCHB59aRecZbRSx0BrvDR_bZV-1W873iXn34kU940C_hc-TaoPnuFDfsJbBYtDSAFWiBfGWBXbxOja0c3NIHhyFqoQ";
"last_name" = xxxx;
name = "xxxx xxxx";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfa1/v/t1.0-1/p50x50/10351160_1463351673922060_1213695234585630315_n.jpg?oh=4c3b52137fc70b5743c7d00c2d=56ECD8DC&__gda__=1456979546_a879ab411cdf61e9293f27f70cd43bdd";
};
};
}
)
This is a facebook Graph API limitation. There is some limitations on the data you can get depending on the role you are. You cannot get your friends email or phone using Graph API.
taggable_friends can ONLY be used for tagging, it does not include any other data. You can only get additional data of friends who authorized your App too.
Btw, you can´t even get the phone of the authorized user, there´s no way to get it at all. And for the email, you have to authorize a user with the email permission.
In general, you can´t get any data of users who did not authorize your App, for privacy reasons.

Resources