0

在我的页面上,人们可以按下分享按钮并在 Facebook 上发帖。我使用这段代码:

window.fbAsyncInit = function() {
    FB.init(
    {
        "appId"  : "<?php echo $fbid; ?>",
        "status" : true,
        "cookie" : true,
        "xfbml"  : true,
        "oauth"  : true
    });

单击功能 showStreamPublish 开始:

function showStreamPublish() {
        FB.ui(
           {
             method: 'feed',
             name: 'Text',
             caption: 'Text',
             link: 'Link',
             picture:'Pic',
             description: 'ni',
             user_message_prompt: 'Share it!'

           },
           function(response) {
                 if (response && response.post_id) {



                    FB.api('/me', function(response) 
        {alert(response.name);
        });  ...

在我使用以下代码的地方,我想显示做 Sahre 的人的用户名,但它没有:(

FB.api('/me', function(response) 
        {alert(response.name);
        }); 

如何获取分享的用户名或用户 ID?它打开警报框 - 内容为“未定义”。谢谢你的帮助。

我试图获取 response.status,但奇怪的是:即使我通过我的应用程序连接并在 Facebook 上发帖,我也会收到一条消息,即我没有通过我的应用程序连接。使用该代码:

    if (response.status === 'connected') {
    // the user is logged in and has authenticated your app
    alert('All good');
    }else if (response.status === 'not_authorized') {
   // the user is logged in but NOT through your app
   alert('Not good');
   }else{
    alert('What the heck?');// the user isn't logged in to Facebook.
  }
 }); 

尼尔

4

1 回答 1

1

我看到两件事我觉得不好:

  • FB.api调用包含在FB.ui.
  • 你使用response了两次:
    • FB.ui({...}, function(response) {...,
    • FB.api('/me', function(response) {....

这两个问题可能相关或无关。但这将使它:

function showUserName() {
    FB.api('/me', function(response) {
        alert('Post was published by ' + response.name);
    });
}
function showStreamPublish() {
    FB.ui({
        method: 'feed',
        name: 'Text',
        caption: 'Text',
        link: 'Link',
        picture: 'Pic',
        description: 'ni',
        user_message_prompt: 'Share it!'
    }, function(response) {
        if (response && response.post_id) {
            showUserName();
        } else {
            alert('Post was not published.');
        }
    }
);
于 2013-03-18T10:26:42.693 回答