user2003356
user2003356

Reputation: 455

Facebook App: Will fb.api method post on friend's wall?

I have tried FB.API method to post on friends wall. It is not working for me. I have surfed a lot. Some of them told that was deprecated. Is there any official information from Facebook regarding this issue? Please help me to know. Thanks.

for your reference,

function postOnMyFriendWall() {
            var body = 'Reading Connect JS documentation';
            FB.api('/friendid/feed', 'post', { message: body }, function(response) {
              if (!response || response.error) {
                alert('Error occured');
              } else {
                alert('Post ID: ' + response.id);
              }
            });
        }

Upvotes: 1

Views: 12236

Answers (2)

Ryan Alexander
Ryan Alexander

Reputation: 569

If you are using iOS you can do something similar using the native FBWebDialogs such as:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                              @"Some stand out message", @"name",
                              @"Some very short description of ?", @"description",
                              @"http://example.com/", @"link",
                              @"http://example.com/img/pic.png/", @"picture",
                              @"12345_friendID", @"to",
                              nil];;
[FBWebDialogs presentFeedDialogModallyWithSession:nil 
                                       parameters:params
                                       handler:^
    (FBWebDialogResult result, NSURL *resultURL, NSError *error) {

        if (error) { 
            NSLog(@"Error publishing story :%@", error);
        } else {
            if (result == FBWebDialogResultDialogNotCompleted) {
                NSLog(@"User cancelled publishing");
            } else {
                NSDictionary *urlParams = [self parseURLParams: [resultURL query]];             
                if (![urlParams valueForKey@"post_id"]) {
                    NSLog(@"User cancelled publishing");
                } else {
                   NSLog(@"You published a story with id:%@", [urlParams valueForKey@"post_id"]);
                }
            }
        }
}];  

- (NSDictionary*)parseURLParams:(NSString *)query {
    NSArray *pairs = [query componentsSeparatedByString:@"&"];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    for (NSString *pair in pairs) {
        NSArray *kv = [pair componentsSeparatedByString:@"="];
        NSString *val =
        [[kv objectAtIndex:1]
        stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        [params setObject:val forKey:[kv objectAtIndex:0]];
    }
    return params;
}

Upvotes: 0

ThePCWizard
ThePCWizard

Reputation: 3348

As of February 6, 2013, you can't post to Friends Timeline with FB.API method.
Read Here: https://developers.facebook.com/roadmap/completed-changes/

Look for feed Dialog or Open Graph Actions as alternative.
Example with Feed Dialog:

function postToFriend() {

    // calling the API ...
    var obj = {
      method: 'feed',
      to: 'friend_id',
      link: 'http://www.facebook.com/thepcwizardblog',
      picture: 'http://fbrell.com/f8.jpg',
      name: 'Feed Dialog',
      caption: 'Tagging Friends',
      description: 'Using Dialogs for posting to friends timeline.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
  }

Complete Documentation for Facebook Dialog: https://developers.facebook.com/docs/reference/dialogs/feed/

Upvotes: 7

Related Questions