2011-06-17 37 views
0

我想有一個feed對話框,我也想使用他的名字或用戶對象。我使用FB.Ui方法。如何在使用Facebook JavaScript SDK的Facebook對話框中使用用戶對象?

<script> 
var publish = { 
    method: 'stream.publish', 
    display: 'popup', // force popup mode 
    attachment: { 
    name: 'I visted this Appp', 
    caption: 'The Facebook Connect JavaScript SDK', 
    description: (
     'A small JavaScript library that allows you to harness ' + 
     'the power of Facebook, bringing the user\'s identity, ' + 
     'social graph and distribution power to your site.' 
    ), 
    href: 'http://fbrell.com/' 
    } 
}; 

FB.ui(publish, Log.info.bind('stream.publish callback')); 
</script> 

正如你可以看到標題是「我訪問過app'.I想將其更改爲Facebook的用戶的第一name..ie‘FIRST_NAME造訪的這個應用程序’..任何人都可以幫助我

回答

1

要獲得有關用戶的信息,首先需要讓他們對您的應用程序進行身份驗證(不需要擴展權限,因爲名稱被視爲「基本」信息)。然後,您可以使用javascript api調用FQL查詢來獲取其名稱,然後使用它填充消息。

驗證用戶:

<fb:login-button autologoutlink="true"></fb:login-button> 

獲取用戶名:

FB.api(
    { 
     method: 'fql.query', 
     query: 'SELECT name FROM user WHERE uid='+FB.getSession().uid 
    }, 
    function(response) { 
      alert(response[0].name); 
    } 
); 
+0

感謝您的回答 – huduga

相關問題