2012-09-04 29 views
0

我寫了下面的代碼,但由於某種原因FB.api不起作用。我可以這樣說,因爲在JavaScript控制檯中沒有日誌消息。我已經對用戶進行了身份驗證,並已獲得publish_stream權限。下面的代碼位於FB.login塊(我希望這不是問題)。我已經使用jQuery,因爲我已經知道如何使獲得請求使用它。問題與FB.api

jQuery.ajax({ 
    url: access, 
    dataType: 'json', 
    success: function (resp) { 
    var data_item='This is a successful post plz do not comment this is a test'; 
    FB.api('me/feed', 'post', {message: data_item}, function(response) { 
    if (!response || response.error) { 
     console.log('Error occured'); 
    } else { 
     console.log('Post ID: ' + response.id); 
    } 
}); 

任何幫助或建議

回答

0

你需要指定接取令牌,我有同樣的問題。我只是添加接取令牌和問題解決了..

到這裏看看:http://www.friendouh.com/

jQuery.ajax({ 
     url: access, 
     dataType: 'json', 
     success: function (resp) { 
     var data_item='This is a successful post plz do not comment this is a test'; 
     FB.api('me/feed', 'post', {message: data_item,access_token: 'your_acess_token'}, function(response) { 
     if (!response || response.error) { 
      console.log('Error occured'); 
     } else { 
      console.log('Post ID: ' + response.id); 
     } 
    }); 
+0

當你O FB.login,在響應中將包含訪問令牌,將其存儲在某個地方,並在需要使用它時調用它 –

+0

我做到了,但它仍然無法正常工作,如果你想我可以給整個代碼 – tumulr