繁体   English   中英

Facebook应用程序:fb.api方法会张贴在朋友的墙上吗?

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

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

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

寻找提要DialogOpen Graph Actions作为替代。
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/

如果您使用的是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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM