Facebook好友的墙贴通过ID发布

时间:2012-11-07 20:35:49

标签: ios xcode facebook

我想在Facebook朋友的墙上发帖,我尝试了这两种方法但没有工作:

1

//post on wall
NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:1];
[variables setObject:@"v" forKey:@"message"];

[graphref doGraphPost:[NSString stringWithFormat:@"1389799421/feed"] withPostVars:variables];
//post on wall

2

 [_facebook requestWithGraphPath:@"1389799421/feed"
                      andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post" forKey:@"message"]
                  andHttpMethod:@"POST"
                    andDelegate:self];

......我无法理解为什么!在Facebook网站上,我添加了捆绑包和权限。

2 个答案:

答案 0 :(得分:2)

  

我想在Facebook好友的墙上发帖

Facebook最近在开发者博客中宣布,通过API will not be possible any more from Feb 2013 on发布到另一个用户的墙上:

  

删除通过图谱API发布到朋友圈的功能

     

我们将删除通过Graph API发布到用户朋友的墙上的功能。具体来说,针对[user_id] / feed的帖子,其中[user_id]与会话用户不同,或者stream_publish调用,其中target_id用户与会话用户不同,将失败。如果您想让人们发布到朋友的时间表,请调用feed dialog

所以我认为现在开始开发这样的功能是没有用的。

答案 1 :(得分:1)

首先,您必须使用发布权限打开会话。具体而言,您必须申请publish_stream权限。

NSArray * permissions = [[NSArray alloc] initWithObjects:@"publish_stream", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
  [self sessionStateChanged:session
                      state:status
                      error:error];
}]; 

如果您具有发布权限,则可以创建并发送请求。确保将access_token作为参数之一。如果不这样做,您将收到身份验证错误。

NSDictionary * postParameters = [NSDictionary dictionaryWithObjectsAndKeys:_textView.text, @"message", FBSession.activeSession.accessToken, @"access_token", nil];
NSString * graphPath = @"ID_NUMBER_HERE/feed";
FBRequest * request = [FBRequest requestWithGraphPath:graphPath parameters:postParameters HTTPMethod:@"POST"];
[[request initWithSession:FBSession.activeSession graphPath:graphPath parameters:postParameters HTTPMethod:@"POST"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
  NSLog(@"Successful posted to Facebook");
  }];
}
相关问题