How to post on Facebook wall without opening Dialo

2020-07-30 00:09发布

问题:

I am trying to integrate facebook in my app. I had done code for login and trying to post on my wall but I don't need the facebook dialog. I want my own. after googling I found some code but its not working. It is not giving any error but not posting any thing...

Here I am using is :

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Facebook developer Test Message",@"message",
                               @"Test it!",@"name",                                   
                               nil];
 Facebook *fb = [[Facebook alloc] init];
    [fb requestWithGraphPath:@"me/feed"   // or use page ID instead of 'me'
                      andParams:params
                  andHttpMethod:@"POST"
                    andDelegate:self];

Its not working..

 FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
     autorelease];
 dialog.userMessagePrompt = @"Enter your message:";
 dialog.attachment = [NSString
   stringWithFormat:@"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.phptab=iphone\",\"caption\":\"Caption\", \"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"];

 [dialog show];

This opens a dialog and ask me to type message and when I clicks It post the Data on my wall.

I Had refferes following links for this

http://forum.developers.facebook.net/viewtopic.php?id=79466

Please tell me where I am doing mistake.

Thanks

回答1:

hi i think you can do this and can solve your problem

NSString *str=@"Your String to post";

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   str,@"message",
                                   @"Test it!",@"name",                                   
                                   nil];
Facebook *fb = [[Facebook alloc] init];
    [fb requestWithGraphPath:@"me/feed"   // or use page ID instead of 'me'
                          andParams:params
                      andHttpMethod:@"POST"
                        andDelegate:self];