这就是我将消息推送到朋友 Facebook 墙上的方式:
在您的 .h 文件中:
#import "FBConnect.h"
#import "FBRequest.h"
#import "FBLoginButton.h"
....
Facebook* _facebook;
NSArray* _permissions;
...
@property (readonly) Facebook *facebook;
在您的 .m 文件中:
@synthesize facebook = _facebook;
在viewDidLoad
:
_permissions = [[NSArray arrayWithObjects:@"user_photos",@"user_videos",@"publish_stream",@"offline_access",@"user_checkins",@"friends_checkins",@"email",@"user_location" , @"read_stream", @"read_friendlist",nil] retain];
_facebook = [[Facebook alloc] initWithAppId:kAppId];
SBJSON *jsonWriter = [[SBJSON new] autorelease];
static NSString* kAppId = @"your app key";
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"your title",@"text",@"http://itunes.apple.com/us/app/facts!/id434894484?l=de&ls=1&mt=8",@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"Title of the post", @"name",
@"Caption of the post", @"caption",
@"Some description", @"description",
nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
@"your friends id", @"to",
nil];
[_facebook dialog: @"stream.publish" andParams:params andDelegate:self];
一件事必须清楚。只有当他确实在您的好友列表中时,您才能发布到好友墙,否则将无法正常工作。我在我的个人资料上测试了代码并且它有效!