2011-01-06 18 views
5

Chcę opublikować coś na ścianie znajomych użytkowników.Jak publikować wiadomości do znajomych za pomocą Facebooka Graph API dla iPhone'a

Używam tego aby umieścić na ścianie użytkownika

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",nil]; 

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

ale muszę odpowiedzieć w moim znajomymi ściany. jak mogę to zrobić?

W tym post wspomniano o targetId muszę coś z tym zrobić.

+0

Wciąż brak odpowiedzi :(Ktoś ans moje pytanie .. – iPrabu

+0

23 dni zniknął i nie ma odpowiedzi ... – iPrabu

Odpowiedz

3

Czy próbowałeś stosując

[facebook requestWithGraphPath:@"[friend_ID]/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

UPDATE:

zamieszczenie na ścianie przyjaciele nie będą więcej pracować z Graph API. Zamiast tego musisz użyć FBDialog.

+0

Każdy profil na FB id jak ten 1405135278. należy ustawić, że jak TA rget_id. – KingofBliss

+0

Spróbowałem tego człowieka .. Wciąż nie używam ... to wpis na mój profil tylko ... – iPrabu

+0

Czy sprawdziłeś swoje konto FB? wysłałem do ur ściany używając tylko tego kodu;) – KingofBliss

0

@mAc

Najpierw musisz autoryzować Facebook. Następnie zaimplementuj metody "FBRequestDelegate" w swojej klasie. Następnie złożyć zamówienie z wykresu API, jak podano poniżej

[facebook requestWithGraphPath:@"/me/friends" andDelegate:self]; 

Gdy wniosek udało, api wywoła metodę delegata „requestDdidLoad”,

-(void)request:(FBRequest *)request didLoad:(id)result { 

    NSLog(@"Result: %@", result); 

} 

Formularz wynik otrzymasz identyfikator strony frieds

0
- (IBAction)InviteAction:(id)sender // Button action 
{ 
    if (!FBSession.activeSession.isOpen) { 
     // if the session is closed, then we open it here, and establish a handler for state changes 
     [FBSession openActiveSessionWithReadPermissions:nil 
              allowLoginUI:YES 
             completionHandler:^(FBSession *session, 
                  FBSessionState state, 
                  NSError *error) { 
              if (error) { 
               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Invite friends process cancelled" 
                            message:nil 
                           delegate:nil 
                         cancelButtonTitle:@"OK" 
                         otherButtonTitles:nil]; 
               [alertView show]; 
              } else if (session.isOpen) { 
               [self InviteAction:sender]; 
              } 
             }]; 
     return; 
    } 

    if (self.friendPickerController == nil) { 
     // Create friend picker, and get data loaded into it. 
     self.friendPickerController = [[FBFriendPickerViewController alloc] init]; 
     self.friendPickerController.title = @"Pick Friends"; 
     self.friendPickerController.delegate = self; 
    } 

    [self.friendPickerController loadData]; 
    [self.friendPickerController clearSelection]; 

    [self presentViewController:self.friendPickerController animated:YES completion:nil]; 
} 

- (void) performPublishAction:(void (^)(void)) action 
{ 
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) 
    { 
     [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"] 
               defaultAudience:FBSessionDefaultAudienceFriends 
              completionHandler:^(FBSession *session, NSError *error) { 
               if (!error) { 
                action(); 
               } else if (error.fberrorCategory != FBErrorCategoryUserCancelled){ 
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied" 
                             message:@"Unable to get permission to post" 
                             delegate:nil 
                           cancelButtonTitle:@"OK" 
                           otherButtonTitles:nil]; 
                [alertView show]; 
               } 
              }]; 
    } else { 
     action(); 
    } 

} 



- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user 
{ 
    self.loggedInUser = user; 
} 


- (void)facebookViewControllerDoneWasPressed:(id)sender 
{ 
    NSMutableString *text = [[NSMutableString alloc] init]; 
    for (id<FBGraphUser> user in self.friendPickerController.selection) 
    { 

     if ([text length]) { 
      [text appendString:@","]; 
     } 
     [text appendString:[NSString stringWithFormat:@"%@",user.id]]; 
    } 

    //For post to friend's wall 
    NSDictionary *params = @{ 
          @"name" : @"Hello Please checkout this app", 
          @"caption" : @" IOS APP", 
          @"description" : @"", 
          @"picture" : @"[email protected]", 
          @"link" : @"http:www.google.com", 
          @"to":text, 

          }; 


    // Invoke the dialog 
    [FBWebDialogs presentFeedDialogModallyWithSession:nil 
              parameters:params 
              handler: 
    ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
     if (error) { 
      NSLog(@"Error publishing story."); 
      UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to Post" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
      [alertshow show]; 
     } else { 
      if (result == FBWebDialogResultDialogNotCompleted) 
      { 
       NSLog(@"User canceled story publishing."); 
       UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to post on your friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
       [alertshow show]; 
      } else { 
       NSLog(@"Story published."); 
       UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Posted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
       [alertshow show]; 
      } 
     }}]; 



    [self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"]; 
} 

- (void)facebookViewControllerCancelWasPressed:(id)sender { 
    [self fillTextBoxAndDismiss:@"<Cancelled>"]; 
} 

- (void)fillTextBoxAndDismiss:(NSString *)text 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
Powiązane problemy