hemant
hemant

Reputation: 1843

Uploading Game Scores to Facebook in iPhone?

i am trying to access facebook in my application to submit scores for my game.. i have registered my application on fb included its api into my xcode project and i am trying to use their sample project to publish the scores using the following code but when i use this code the message is posted on my wall but not all the details are included as used in NSMutabledictionary ..what am i possibly doing wrong??

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

}

only the SHARE ON FACEBOOK message is posted on my wall along with the name of my application and rest i am not able to figure out how to use... any help will be appreciated??

Upvotes: 0

Views: 4119

Answers (2)

brs
brs

Reputation: 299

As pointed our by @hemant "stream.publish" is missing. That seems to be all that is missing from the DemoApp included with the Facebook SDK.

Upvotes: 0

Rajavanya Subramaniyan
Rajavanya Subramaniyan

Reputation: 2155

Here is a modified PublishStream function that works.

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

}

Upvotes: 4

Related Questions