我已经使用了 Graph API,并且已经成功登录 Facebook 并获得了好友列表。
现在我需要在墙上贴一条消息。如何?
使用 url 在墙上发帖,并使用此方法在墙上发帖
- (void)postToWall
{
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.php?tab=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];
}
如果您想发布到您的墙上认为您的 FB 应用程序不显示对话框,您可以这样做
NSString *message = @"some text";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, @"message",nil];
[fb requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; //fb here is the FaceBook instance.
并且您肯定会在用户登录并授权权限后执行此操作。
您还可以从facebook官方发布的demo “Hackbook for iOS”中学习如何发布墙和其他iOS Facebook开发的基本实践
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];
[variables setObject:@"this is a test message: postMeFeedButtonPressed" forKey:@"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"yourFriendFbID/feed" withPostVars:variables];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];