使用FBGraph API(iOS7和iOS6)在Facebook上的朋友墙上发布消息/图片

时间:2014-01-09 12:18:38

标签: objective-c facebook-graph-api ios7

我正在开发应用程序,我将从我的帐户中检索Facebook用户ID。现在我想直接使用我的应用在朋友的墙上发布消息或图片。我正在使用fbgraph API。

我希望此功能适用于iOS7和iOS6。可能吗? 我已经尝试过这段代码但我无法收到任何回复。

[_facebook requestWithGraphPath:@"[user_id]/feed"  andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post"forKey:@"message"]

andHttpMethod:

@"POST"andDelegate:self];

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你可以采取两种方式......

按图表APi 写在你的班级:

  
      
  • (void)performPublishAction:(void(^)(void))action {   //我们将发布权限的请求推迟到发布时刻,然后我们检查权限   // publish_actions   if([FBSession.activeSession.permissions indexOfObject:@“publish_actions”] == NSNotFound){       //如果我们还没有这个权限,那么我们现在就请求它       [FBSession.activeSession requestNewPublishPermissions:@ [@“publish_actions”]                                             defaultAudience:FBSessionDefaultAudienceFriends                                           completionHandler:^(FBSession * session,NSError * error){                                               if(!error){                                                   行动();                                               }                                               //对于此示例,请忽略错误(例如,如果用户取消)。                                           }];   } else {       行动();   }}
  •   

并在您的share_btn方法中:

  

[self performPublishAction:^ {

            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           @"My Name", @"name",
                                           url, @"link",
                                           @"I am a Good guy", @"caption",
                                           @"I love Arsenal", @"description",
                                           @"http://en.wikipedia.org/wiki/File:Arsenal_FC.svg", @"picture"],
                                           nil];

            [FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"
                                  completionHandler:^(FBRequestConnection *connection, id result,
     

NSError *错误)                   {                                             if(error){                                                 NSLog(@“发布故事时出错:%@”,错误);                                             } else {                                                 NSLog(@“已成功发布的故事”);                                             }                   }];

        }];

提供图片链接,请注意此图谱API不显示模式弹出以供分享。

通过SLCompose

#import <Social/Social.h>
#import <Accounts/Accounts.h>
  

__弱SLComposeViewController * controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[controller setInitialText:[SocialIntegrationNative appShareText]];

[controller addImage:[UIImage imageNamed:@"xyz.png"]];

__block SLComposeViewController *shareController = controller;

[controller setCompletionHandler:^(SLComposeViewControllerResult result) {

    switch (result) {
        case SLComposeViewControllerResultCancelled:

            break;
        case SLComposeViewControllerResultDone:

            break;

        default:
            break;
    }


}];