kolenda
kolenda

Reputation: 2811

Facebook app stopped to post friends photos, after iOS 7 and SDK 3.10 update

I'm creating a simple iOS application that will take a picture, modify it and post it on some of your friends account. On a 'share' command the app will show the FB FriendPicker letting you select one of your friends.

I had this working when I used iOS 6 and FB SDK ~3.7, the working code is below:

NSString* friendId;
for (id<FBGraphUser> user in self.friendPickerController.selection) {
    friendId = user.id;
}

AppDelegate * appDelegate = (AppDelegate*) [ [UIApplication sharedApplication] delegate ];
UIImage *img = appDelegate.imageAnalyzed;

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"Some message" forKey:@"message"];
[params setObject:UIImagePNGRepresentation(img) forKey:     //@"source"];  //I tried all of them...
                                                        @"image"];
                                                            //@"picture"];
[params setObject:@"true" forKey: @"fb:explicitly_shared"];

NSString* strId = [NSString stringWithFormat:@"%@/photos", friendId];

[FBRequestConnection startWithGraphPath: strId
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)   
  {
     if (error)
     {
         //showing an alert for failure
         [self showAlert:@"Error posting photo." result:result error:error];
     }
     else
     {
         [self performSegueWithIdentifier:@"goToAfterFBSegue" sender:self];
     }
 }];

So here's the problem:

When I upgraded iOS to 7.0 and Facebook SDK to 3.10 then this code stopped working. But when I replace the:

NSString* strId = [NSString stringWithFormat:@"%@/photos", friendId];

with:

NSString* strId = @"me/photos";

it works and adds the picture to my account. I tried to find anything related to recent changes on FB but the official doc says that there weren't any functionality changes since then, only 'bug fixes'.

I've also found another code example, that used startForPostWithGraphPath instead of startWithGraphPath like this:

NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
[action setObject:@"From Friendalizer:" forKey:@"message"];
[action setObject:UIImagePNGRepresentation(img) forKey:   //  @"source"];
                                                            @"image" ];
                                                        //@"picture"];

[FBRequestConnection startForPostWithGraphPath: @"me/myapp:post"
                                   graphObject:action
                             completionHandler:^(FBRequestConnection *connection,
                                                 id result,
                                                 NSError *error)

And this code also gives me errors, the difference is that the error in first version is "com.facebook.sdk:ErrorSessionKey" with HTTPStatusCode 403, the second version returns HTTPStatusCode 400 :].

Do you have any idea how to fix this issue?

BTW: I understand it may be stupid or wrongly described question for some of you, but this is my very first iOS application and first FB app so I feel I'm going blind here...

Upvotes: 0

Views: 1436

Answers (1)

Gyanendra Singh
Gyanendra Singh

Reputation: 1483

As of now (as per the latest Facebook API) posting to friends wall using the Graph path is removed. Only way we can share the image of friends wall is using the Feed Dialog method

-(void)postToFriendsWall{

    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
    NSString *greetingMessage = [self greetingTextView].text;

     // Set the Friends ID here in dictionary
    [dictionary setObject:fbUserDAO.uID forKey:@"to"];

     // Add Link attributes
    [dictionary setObject:@"www.github.com" forKey:@"link"];
    //[dictionary setObject:@"ADD_CAPTION" forKey:@"caption"];
    [dictionary setObject:@"Go for Git" forKey:@"name"];
    [dictionary setObject:@"A repository for all..." forKey:@"description"];


       NSString *imageURL = @"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png";

         //  embedded action along with Like, Comment and Share
        NSString *actionsString = [[NSString alloc]initWithFormat:@"[{'name': 'Show Card', 'link': '%@'}]",imageURL];
        [dictionary setObject:actionsString forKey:@"actions"];
        [dictionary setObject:imageURL forKey:@"picture"];

       [self showFeed:dictionary];
}

And then present a feed dialog using the Below code

-(void)showFeed:(NSDictionary *)paramDict{

   [FBWebDialogs presentFeedDialogModallyWithSession:[FBSession activeSession]
                                           parameters:paramDict
                                              handler:
     ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
         for (UIView *currentView in self.tabBarController.selectedViewController.view.subviews) {

             if ([currentView isKindOfClass: [LoadingView class]]) {
                 [currentView removeFromSuperview];
             }

         }

         if (error) {
     NSLog("An error"); 
     }
}

Below is the feed dialog output(Image link you wish to post on your friends wall)

enter image description here

Upvotes: 1

Related Questions