Building Facebook IOS friend multi-selector - ios

I want to build a friend multiselector so that my user can send a request to anyone of his friends. I know that there is the FBfriendselectorcontroller, but it does not have the option to select all friends, and I would like to have it in my app. I tried to populate a UITableview manually by getting the friend list in this way:
permissions (logged in using the log-in button):
NSArray *permissions = [[NSArray alloc] initWithObjects:#"public_profile", #"email", #"user_friends", nil];
self.loginView.readPermissions = permissions;
data:
[FBRequestConnection startWithGraphPath:#"me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
//NSArray *data = [result objectForKey:#"data"];
NSLog(#"%#", result);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:#"%#", result], #"to", #"send", #"action_type", #"YOUR_OBJECT_ID", #"object_id", nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Take this bomb to blast your way to victory!"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];
}];
the friend count returns 318, but the "data" is like this: (). I also tried the:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error){
NSArray* friends = [result objectForKey:#"data"];
but the data is null. What am I doing wrong??!!

Related

How to post on Facebook page as Page Post from app via graph API in iOS?

I am trying to post on Facebook page as a page post. I using am below graph code API, but post coming on side as other people post, not as page admin/Page itself:
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Testing Post", #"name",
#"This is testing", #"message",
#"this is description", #"description",
nil];
NSString *feed = [NSString stringWithFormat:#"/Page ID/feed"];
[FBRequestConnection startWithGraphPath:feed
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
if(!error){
NSLog(#"%#", result);
}
else{
NSLog(#"Error %#", error);
}
}];
If you want to post as the Page itself, you'll need to use a Page Access Token with the publish_pages permission.
See
https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
Here is Complete Answer
NSString *accesstoken = <Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

How to post status feed on Facebook page as pageadmin in iOS?

I want to post status on my Facebook page. Status should be shown on Facebook as a page status not status from any username or from my name.
I tried below code,
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"This is a check for page post message", #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/1521177224766299/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if (result)
{
NSLog(#"Result %#", result);
}
else
{
NSLog(#"%#", error);
}
}];
a message status was posted done page wall but that status come from my name.
But when I tried to hit same post method with page_id/feed POST Query and with same parameter #"this is my status" #"message" from graph api explorer page, it posted status from page not from me.
Please help.
NSString *accesstoken=[NSString stringWithFormat:#"%#","here add your page access_token"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
accesstoken, #"access_token",
postingString, #"message",
// #"http://www.real-timesports.com", #"link",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
NSLog(#"requestToPost==%#",requestToPost);
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"facebook result >> %#", result);
}];
[requestToPostConnection start];
Here is Complete Answer
NSString *accesstoken = <Facebook_Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

not getting facebook friend list

i am getting null in friends list this is my code
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
arrFriendFB = [result objectForKey:#"data"];
arrFriendFB=[arrFriendFB valueForKey:#"first_name"];
NSLog(#"friemd=%#",arrFriendFB);
NSLog(#"friends description :%#",[arrFriendFB description]);
}];
}
As new facebook APi doc there is some modification. see some change's mention below
first you need to get access token with "user_friends" permission.
its graph API url:-
https://graph.facebook.com/me/friends?access_token=
For more information follow this link
https://developers.facebook.com/docs/facebook-login/permissions/v2.0
use this method to get friend list.
-(void)getFriendList
{
[FBSession setActiveSession:[self appDelegate].session];
FBRequest *friendRequest = [FBRequest requestForGraphPath:#"me/friends?fields=name,picture,location"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSArray *data = [result objectForKey:#"data"];
//NSLog(#"response : %#",data);
for (FBGraphObject<FBGraphUser> *friend in data)
{
NSLog(#"name : %#",[friend name]);
}
}];
}

How to get large picture size from Facebook graph API for news feed

I am stuck with getting picture from Facebook Graph API for news feed with small size. This is the url I get https://fbcdn-photos-b-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10363492_10202184985725870_7374705736674502849_s.jpg. Not sure how will get the picture with size o.jpg
Finally, figured it out. Here is what I did.
NSString *query = [NSString stringWithFormat:#"SELECT pid, object_id, src_big, src_big_width, src_big_height FROM photo WHERE object_id = %#", wallPost[#"object_id"]]; //begins from SELECT........
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"q",
nil];
[FBRequestConnection startWithGraphPath:#"/fql" parameters:params HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
//do your stuff
if (!error) {
NSArray *photo = [result objectForKey:#"data"];
NSString *photoString = [[photo valueForKey:#"src_big"]componentsJoinedByString:#""];
//NSLog(#"result %# %#", photoString);
}
}];

Get friends' work data from facebook SDK on iOS

I am trying to fetch work info for FB friends on iOS using Facebook SDK. Here's the code that I am using:
if (FBSession.activeSession.isOpen) {
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"work", #"fields",
nil];
FBRequest *request = [FBRequest requestWithGraphPath:#"me/friends" parameters:params HTTPMethod:#"GET"];
[request startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary *result, NSError *error) {
if (!error) {
if (result) {
if (result.count) {
NSMutableArray *friendsWithJobTitles = [NSMutableArray array];
for (id aFriend in [result objectForKey:#"data"]) {
if ([aFriend objectForKey:#"work"]) {
[friendsWithJobTitles addObject:aFriend];
}
}
NSLog(#"result = %#", friendsWithJobTitles);
}
}
}
}];
}
The friendsWithJobTitles is always blank for some reason. Please help.

Resources