简体   繁体   English

如何在iPhone中使用fbrequest以编程方式在Facebook朋友墙上发布信息?

[英]how to post on facebook friends wall using fbrequest programmatically in iphone?

I searched every where but not getting the single hint how to do that....i got some code also but it is not working ... can anyone suggest me any tutorial or sample code to do that !!! 我搜索了所有地方,但没有得到任何提示,该怎么做...。我也得到了一些代码,但是它没有用...任何人都可以建议我使用任何教程或示例代码来做到这一点!!! thanks in advance i am trying following code:: 在此先感谢我正在尝试以下代码::

-(void)inviteFriend:(CustomButton *)sender
{

    NSString *str=[NSString stringWithFormat:@"%@/feed",sender.inviteUserId];
    if (FBSession.activeSession.isOpen)
    {
        //UIImage *image = [UIImage imageNamed:@"testImage.png"];

        hudApp = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hudApp.labelText = @"Page Sharing...";
        [self performSelector:@selector(timeout:) withObject:nil afterDelay:60*5];

        // NSString *fbMessage = [NSString stringWithFormat:@"test"];
        NSString *fbMessage = @"hello testing";


        NSMutableDictionary* params=[NSDictionary dictionaryWithObjectsAndKeys:fbMessage, @"message", FBSession.activeSession.accessToken, @"access_token", nil];

        NSLog(@"feed::%@",str);

        [FBRequestConnection startWithGraphPath:str
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection, id result,NSError *error) {
                                  NSLog(@"result::%@",result);


                 if(error)
                 {
                  NSLog(@"fail : %@",error.localizedDescription);
                hudApp.labelText = [NSString stringWithFormat:@"%@",error.localizedDescription];
                                  }
                                  else
                                  {
                                      NSLog(@"Success facebook post");
                                      hudApp.labelText = [NSString stringWithFormat:@"Success"];
                                      // txtView.text = @"success";
                                      NSLog(@"success");
                                  }

                                  hudApp.mode = MBProgressHUDModeCustomView;
                                  [self performSelector:@selector(dismissHUD:) withObject:nil afterDelay:1.0];
                              }];
    }
    else
    {
        NSArray *permissions = [NSArray arrayWithObject:@"publish_stream"];
        [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES
                          completionHandler:^(FBSession *session, FBSessionState state,NSError *error) {
                                      NSLog(@"session.permissions ? : %@", session.permissions);
                                      [self sessionDoneForPageShare:session state:state error:error withuserid:str];
                                  }
         ];
    }


}


-(void)sessionDoneForPageShare:(FBSession *)session state:(FBSessionState)state error:(NSError *)error withuserid :(NSString *)usreid
{
    //UIImage *image = [UIImage imageNamed:@"testImage.png"];

    NSLog(@"feed::%@",usreid);
    hudApp = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hudApp.labelText = @"Page Sharing...";
    [self performSelector:@selector(timeout:) withObject:nil afterDelay:60*5];

    //NSString *fbMessage = [NSString stringWithFormat:@"test"];
    NSString *fbMessage = @"hello testing";

    NSLog(@"State : %d **** Facebook Message : %@",state,fbMessage);

   // NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: fbMessage, @"message", nil];

    NSMutableDictionary* params=[NSDictionary dictionaryWithObjectsAndKeys:fbMessage, @"message", FBSession.activeSession.accessToken, @"access_token", nil];

    [FBRequestConnection startWithGraphPath:usreid
                         parameters:params
                         HTTPMethod:@"POST"
                  completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                              if(error)
                              {
                                  NSLog(@"fail : %@",error.localizedDescription);
                                  // txtView.text = [NSString stringWithFormat:@"%@",error.localizedDescription];
                                  NSLog(@"%@",[NSString stringWithFormat:@"%@",error.localizedDescription]);
                                  hudApp.labelText = [NSString stringWithFormat:@"%@",error.localizedDescription];
                              }
                              else
                              {
                                  NSLog(@"Success facebook post");
                                  hudApp.labelText = [NSString stringWithFormat:@"Success"];
                                  //txtView.text = @"success";
                                  NSLog(@"success");
                              }

                              hudApp.mode = MBProgressHUDModeCustomView;
                              [self performSelector:@selector(dismissHUD:) withObject:nil afterDelay:1.0];
                          }];
}

In order to post to a friend's wall, you need to make a request to /{friend_id}/feed . 为了发布到朋友的墙上,您需要向/{friend_id}/feed发送请求。 However, Facebook has disabled posting to friends' wall since February 6, 2013 : 但是, 自2013年2月6日起 ,Facebook已禁止在朋友的墙上张贴文章

Removing ability to post to friends walls via Graph API 删除通过Graph API发布到朋友墙的功能

We will remove the ability to post to a user's friends' walls via the Graph API. 我们将删除通过Graph API发布到用户朋友的墙上的功能。 Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. 具体而言,针对[user_id]与会话用户不同的[user_id] / feed张贴,或target_id用户与会话用户不同的stream.publish调用将失败。 If you want to allow people to post to their friends' timelines, invoke the feed dialog. 如果要允许人们发布到朋友的时间表上,请调用供稿对话框。 Stories that include friends via user mentions tagging or action tagging will show up on the friend's timeline (assuming the friend approves the tag). 通过用户提及标记或动作标记包含好友的故事将显示在好友的时间轴上(假设好友批准了该标记)。 For more info, see this blog post. 有关更多信息,请参见此博客文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM