使用iOS Facebook SDK发布到朋友墙

时间:2013-01-09 10:05:34

标签: ios facebook facebook-graph-api ios6

  

可能重复:
  Facebook API: Post on friend wall

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

 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];

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

1 个答案:

答案 0 :(得分: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];

有一点必须清楚。当他真的在你的朋友列表中时,你只能发布到朋友的墙上,否则它将无效。我在我的个人资料中测试了代码并且它有效!

相关问题