1

我已经尝试过 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);
              }
            });
        }
4

2 回答 2

7

自 2013 年 2 月 6 日起,您无法通过FB.API方法发布到好友时间线。
在这里阅读:https ://developers.facebook.com/roadmap/completed-changes/

寻找feed DialogOpen Graph Actions作为替代方案。
提要对话框示例:

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/

于 2013-03-15T06:37:18.177 回答
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;
}
于 2014-07-18T07:18:28.140 回答