Facebook API: Post on friend wall - iphone

Is it possible to post something on a users friends wall, without having to get all the friends first (So you can get the friend id)?
[facebook requestWithGraphPath:#"me/friends" andDelegate:self];

See this
-(IBAction)PostToBuddyWall
{
NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init];
[postVariablesDictionary setObject:#"LOL" forKey:#"name"];
[postVariablesDictionary setObject:self.postTextView.text forKey:#"message"];
[objDelegate.facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/feed",friendId] andParams:postVariablesDictionary andHttpMethod:#"POST" andDelegate:nil];
NSLog(#"message: %#",postVariablesDictionary);
[postVariablesDictionary release];
UIAlertView *facebookAlter=[[UIAlertView alloc] initWithTitle:#"Message" message:#"Posted successfully on facebook" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil, nil];
[facebookAlter show];
[facebookAlter release];
[self dismissModalViewControllerAnimated:YES];
}

You can get the friends of the logged in user by issuing a request to me/friends.
Then you can create a ui element that shows the list of friends and the user can select the ones he want to share with.
Then, after the user selected you simply post on their walls by issuing a POST to FRIEND_ID/feed (Feed connection of the User object).
You'll need to have the publish_stream permissions which lets you: Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends (http://developers.facebook.com/docs/authentication/permissions/)

Related

How can we like a url using FB Login?

I want to like a url using a like button as shown in the given link.
At bottom Like button is there
click on the like button will like this page and shows in your facebook profile page under Activity block as shown below:
How can we like a url like that in iPhone App.If user is login with fb then just like if not login then login and then like.
Thanks in Advance.
are you looking for this : Facebook like button
Finally, I have done it.
Code to like Page URL using graph API is as Follows:
- (IBAction)likepageonFB:(id)sender
{
[appDelegate openSession];
NSString *likePage=#"http://www.facebook.com/ipreencekmr";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
likePage, #"object",[[NSUserDefaults standardUserDefaults] valueForKey:#"token"],#"access_token",
nil];
[FBRequestConnection startWithGraphPath:#"/me/og.likes" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:#"liked with id %#",[result valueForKey:#"id"]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
NSLog(#"result is %#",result);
}];
}
You can check this example I have uploaded FBLike Button

how to get facebook friend list using new graph API

i am currently develop an app in which i need to add friend's from facebook friend list using new facebook graph API.
This is my code:
_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"publish_stream", #"offline_access",#"read_friendlists",nil] retain];
[facebook authorize:_permissions];
facebook = [[Facebook alloc] initWithAppId:#"fbid" andDelegate:self];
[facebook requestWithGraphPath:#"me" andDelegate:self];
[facebook requestWithGraphPath:#"me/friends" andDelegate:self];
NSMutableDictionary*params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"4",#"uids", #"name", #"fields", nil];
[facebook requestWithMethodName:#"user.getInfo" andParams:params andHttpMethod:#"GET" andDelegate:self];
but every time it give me error in console
please help me...
Here you have a code sample that fetches the friends info:
[facebook requestWithGraphPath:#"me/friends"
andParams:[ NSDictionary dictionaryWithObjectsAndKeys:#"picture,id,name,link,gender,last_name,first_name",#"fields",nil]
andDelegate:self];
Remember to:
implement the proper delegate methods
You must call authorize before fetching the friends information. This way the user will be able to login first.
I hope this helps, cheers
I think you should swap. Otherwise it's not working.
this is correct way:
facebook = [[Facebook alloc] initWithAppId:#"fbid" andDelegate:self];
[facebook authorize:_permissions];
$friend_list =json_decode(file_get_contents("https://graph.facebook.com/$uid/friendlists?access_token=$access_token"),true);
$friend_list_array = $friend_list['data'];
foreach($friend_list_array as $key=> $value){
$inner_array_name[$value['id']][]=$value['name'];
}

Getting Facebook ID number with API

I know - I have read the documentation - but frankly Facebook is horrible at it. I can't figure out how to send a request that illicits a response. Here's what I'm trying:
NSURL *fbID = [NSURL URLWithString:#"https://graph.facebook.com/me?fields=id"];
fbUserID = [[NSData alloc] initWithContentsOfURL: fbID];
Where should this code go? Is there a specific class it is looking for if I have set 'self' as delegate?
How are you trying to integrate FB into your app? I have been looking into Facebook connect recently and found their documentation very helpful (http://developers.facebook.com/docs/guides/mobile/#ios). I know you said you looked at the documentation, but for me after going through their steps for iOS I was able to make an app that allowed users to sign in and give me access to their basic information, including ID. After going through authorization, I had the following code in my app delegate:
- (void) fbDidLogin {
//get information about the currently logged in user
[facebook requestWithGraphPath:#"me" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSString *name = [result objectForKey:#"name"];
NSString *msg = [[NSString alloc] initWithFormat:#"To prove this works, your name is %#",name];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thanks for Logging In!"
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
This gets the user's full name after logging in and displays it. You can do the same thing for getting their ID.

Getting publish_stream extended permission from the user

I was ussing Facbook connect in my iPhone app, but in december the posts stopped working. After some research I found that i'm supossed to use stream.publish, something like:
NSString *att = #"{\"bob\":\"i\'m happy\",\"caption\": \"User rated the internet 5 stars\", \"description\": \"a giant cat\"}";
NSDictionary *attachment = [NSDictionary dictionaryWithObject:att forKey:#"attachment"];
[[FBRequest requestWithDelegate:self] call:#"facebook.stream.publish" params:attachment];
Which i think it's correct, but the posts still don't work. Someone told me that i need to get publish_stream extended permission from the user, but i dont know how to do that.
Present the FBPermission dialog and ask the user for the extended permission
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] initWithSession:session] autorelease];
dialog.delegate = self;
dialog.permission = #"publish_stream";
[dialog show];

iphone : FBConnect Auto post to user wall

i want to auto post to a user wall from my iphone applications ( without that "publish" "skip" dialog box ). how i can do that ?
the following should be called in the class that implements FBSessionDelegate and FBRequestDelegate:
Facebook *_facebook = [[Facebook alloc] initWithAppId:kAppId];
NSArray *_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"offline_access",nil] retain];
[_facebook authorize:_permissions delegate:self];
And that is the call for fb post (should be used in the same class):
NSString *message = #"This is the message I want to post";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message",
nil];
[_facebook requestWithMethodName:#"stream.publish"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
If you want to post a message on the wall of other user you should include "uid" parameter in your params dictionary. Please consult http://developers.facebook.com/docs/reference/rest/stream.publish/
P.S. There are all the necessary examples in the iPhone Facebook connect SDK sample code, so please do not afraid to investigate just a little bit ;)