Facebook App:fb.api方法会在朋友的墙上张贴吗?

时间:2013-03-14 17:05:52

标签: facebook facebook-graph-api

我已经尝试过FB.API方法在朋友墙上发帖。它不适合我。我冲浪了很多次。他们中的一些人告诉他们已被弃用。 Facebook是否有关于此问题的官方信息?请帮我知道。感谢。

供您参考,

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);
              }
            });
        }

2 个答案:

答案 0 :(得分:7)

截至2013年2月6日,您无法使用FB.API方法发布到朋友时间轴 请阅读:https://developers.facebook.com/roadmap/completed-changes/

寻找 Feed对话打开图表操作作为替代方案。
Feed对话框示例:

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);
  }

Facebook对话的完整文档:https://developers.facebook.com/docs/reference/dialogs/feed/

答案 1 :(得分:0)

如果您使用iOS,则可以使用本机FBWebDialogs执行类似操作,例如:

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;
}