3

可能重复:
Facebook API:在朋友墙上发帖

我正在尝试将消息发布在朋友墙上。但它不适用于我下面的代码,

 NSMutableDictionary* params = [NSMutableDictionary dictionary];
 [params setObject:@"Some text" forKey:@"user_message_prompt"];
 [params setObject:@"another text" forKey:@"action_links"];

 [facebook requestWithGraphPath:@"****FB ID here *****/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

我尝试了很多方法来解决它,但找不到解决方案。请让我知道我在代码中做错了什么。我需要快速帮助来解决。

4

1 回答 1

0

这就是我将消息推送到朋友 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];

一件事必须清楚。只有当他确实在您的好友列表中时,您才能发布到好友墙,否则将无法正常工作。我在我的个人资料上测试了代码并且它有效!

于 2013-01-09T10:12:39.573 回答