2

How to post message on Facebook friend's wall using NEWFacebook SDK selecting target_id of friend.

halfer
  • 19,824
  • 17
  • 99
  • 186
Aarti
  • 51
  • 3

3 Answers3

5
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:[NSString stringWithFormat:@"Hi."] forKey:@"message"];
[variables setObject:@"http://icon.png" forKey:@"picture"];       //http://tinyurl.com/45xy4kw
[variables setObject:@"Create post" forKey:@"name"];
[variables setObject:@"Write description." forKey:@"description"];

[_facebook requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",facebook_user_id] 
                      andParams:variables 
                  andHttpMethod:@"POST"
                    andDelegate:self];
Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43
  • Nice Answer, could you tell me one thing, if i wanted to show a picture from my app then how can i modify the code (line no.3) – mAc Nov 28 '11 at 07:39
  • Whatever picture you want to upload on facebook, You need url of that picture first and replace it with "http://icon.png" url. – Jatin Patel - JP Dec 03 '11 at 04:57
  • If i am having an Image that i have to post which is on my mAcintosh Drive then how could we do that..?i Am asking this actually.. – mAc Dec 05 '11 at 04:15
0

 NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"https://developers.facebook.com/docs/reference/dialogs/",@"link",
                                   @"Facebook Dialogs",@"name",
                                   @"Reference Documentation",@"caption",
                                   @"Using Dialogs to interact with users.",@"description",
                                   @"Facebook Dialogs are so easy!",@"message",
                                   nil];
   // [facebook requestWithGraphPath:@"me/feed" andParams:params andDelegate:self];
    //[facebook requestWithMethodName:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
Sishu
  • 1,510
  • 1
  • 21
  • 48
0

check delegate methodes

-(void)fbDidLogin
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [facebook requestWithGraphPath:@"me/picture" andDelegate:self];
    NSLog(@"Login Success with :%@   %@",facebook.accessToken,facebook.expirationDate);

}
-(void)fbDidLogout
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
    {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
    NSLog(@"Logout Success");
}
-(void)request:(FBRequest *)request didLoad:(id)result 
{
    if(c==0)
    {
        NSData *data = [NSData dataWithData:(NSData*)result];
        UIImage *profilePic = [[[UIImage alloc] initWithData:data] autorelease];
        image1.image=profilePic;
        [self postWall];

        // NSLog(@"response is %@", result);       
        //  NSString *email =[result objectForKey:@"name"];
        // NSString *userFbId =[result objectForKey:@"id"];
        // NSLog(@"%@",email);
        // NSLog(@"%@",userFbId);
          c=1;
    }
    else
    {
        NSLog(@"%@",result);
        NSLog(@"posted!!") ;
    }
}

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error
{

    NSLog(@"Failed with error: %@", [error localizedDescription]);

}


Sishu
  • 1,510
  • 1
  • 21
  • 48