试图获取response.name或id

时间:2013-03-18 09:52:08

标签: javascript facebook

在我的页面上,人们可以按分享按钮并在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);
        }); 

如何获取执行共享的persob的用户名或用户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.
  }
 }); 

尼尔

1 个答案:

答案 0 :(得分: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.');
        }
    }
);