在iPhone上将游戏分数上传到Facebook?

时间:2011-01-15 11:23:42

标签: iphone facebook ios4

我想在我的应用程序中访问facebook以提交我的游戏分数..我已经在fb上注册我的应用程序将其api包含到我的xcode项目中,我正在尝试使用他们的示例项目使用以下内容发布分数代码,但当我使用此代码时,消息发布在我的墙上,但并未包含 NSMutabledictionary 中使用的所有详细信息..我可能做错了什么?

- (IBAction)publishStream:(id)sender {



 SBJSON *jsonWriter = [[SBJSON new] autorelease];

  NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                               @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];



  NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
  NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"a long run", @"name",
                               @"The Facebook Running app", @"caption",
                               @"it is fun", @"description",
                               @"http://itsti.me/", @"href", nil];


  NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 @"Share what on Facebook",  @"user_message_prompt",
                                 actionLinksStr, @"action_links",
                                 attachmentStr, @"attachment",
                                 nil];


  [_facebook dialog:@"feed"
          andParams:params
        andDelegate:self];

}

只有 SHARE ON FACEBOOK 消息与我的应用程序名称一起发布在我的墙上并且休息我无法弄清楚如何使用...任何帮助将不胜感激?

2 个答案:

答案 0 :(得分:4)

这是一个有效的修改后的PublishStream函数。

- (void)publishStream:(id)sender {

    SBJSON *jsonWriter = [[SBJSON new] autorelease];

    NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];

    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"a long run", @"name",
                                @"The Facebook Running app", @"caption",
                                @"it is fun", @"description",
                                @"http://itsti.me/", @"href", nil];
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"Share on Facebook",  @"user_message_prompt",
                                   actionLinksStr, @"action_links",
                                   attachmentStr, @"attachment",
                                   [NSString stringWithFormat:@"I scored %d on mycoolgame, Think you can beat me? - http://bit.ly/cJtBkE", totalScore],@"message",
                                   nil];

    [_facebook dialog:@"feed"
            andParams:params
          andDelegate:self];

}

答案 1 :(得分:0)

正如我们所指出的那样,@ hemant“stream.publish”缺失了。这似乎是Facebook SDK附带的DemoApp所缺少的。