2013-04-26 65 views
0

我正在構建一個Web應用程序,我需要將其與Facebook連接。我的最終目標是將照片張貼到用戶牆上和相冊中,但我已經碰到了磚牆。Facebook JS API的行爲與不同的appid不同

當使用我自己的app_id(我自己的,我的意思是我用我自己的Facebook帳戶創建了這個「測試」應用程序),它完美地工作 - 圖片張貼在用戶牆和相冊上。但是,當客戶使用app_id(客戶使用自己的帳戶創建此應用程序時,我以開發人員身份在此列出)時,它的行爲會有所不同 - 用戶牆上不會顯示任何圖片。

我檢查了設置,它們是相同的。代碼,一樣。回覆我在發佈圖片時從facebook獲得 - 不同。

下面是我使用的代碼:

<button>share photo</button> 
<div id="fb-root"></div> 
<script> 
var graph_url = 'https://graph.facebook.com/me/photos?access_token='; 
var photo_url = '<?php echo $photo_url; ?>'; 
var user_id = null; 
var access_token = null; 

window.fbAsyncInit = function() { 
    // init the FB JS SDK 
    FB.init({ 
     appId  : '<?php echo $app_id; ?>',      // App ID from the app dashboard 
     channelUrl : '//my-website/channel.php', // Channel file for x-domain comms 
     status  : true,         // Check Facebook Login status 
     xfbml  : true         // Look for social plugins on the page 
    }); 

    // Additional initialization code such as adding Event Listeners goes here 
    FB.getLoginStatus(function(response) { 
     if (response.status === 'connected') { 
      user_id = response.authResponse.userID; 
      access_token = response.authResponse.accessToken; 
     } else if (response.status === 'not_authorized') { 
      // nothing to do 
     } else { 
      FB.login(function(response) { 
       if (response.authResponse) { 
        user_id = response.authResponse.userID; 
        access_token = response.authResponse.accessToken; 
       } 
      }); 
     } 
    }); 

    $('button').on('click', function(ev) { 
     if (user_id && access_token) { 
      FB.api('/me/photos', 'post', { 
       url: photo_url, 
       message: 'dasdad', 
       access_token: access_token 
      }, function(response) { 
       console.log(response); // <---- this different 
      }); 
     } 
    }); 
}; 

// Load the SDK asynchronously 
(function(d, s, id){ 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 
</script> 

此代碼日誌,以idpost_id(我app_id,像它應該),或只是id(與客戶app_id)。我完全迷失在這裏,任何人都可以將我指向正確的方向?我在這裏做錯了什麼?這是在Facebook側的錯誤?

+1

我沒有看到你問任何權限當你登錄 - 所以我假設你的應用程序可能仍然有該權限是因爲您之前提供了該權限,但其他應用程序不具備該權限。請將訪問令牌記錄到兩個應用的瀏覽器控制檯,然後在此處查看https://developers.facebook.com/tools/debug – CBroe 2013-04-26 14:24:17

+0

謝謝!就是這樣!你是否也可以添加這個答案,以便我可以接受它? – Kristian 2013-04-26 15:00:34

回答

1

我沒有看到您在進行登錄時詢問任何權限 - 因此我認爲您的應用可能仍然具有該權限,因爲您之前已提供該權限,但其他應用沒有該權限。

請登錄訪問令牌兩種應用程序瀏覽器控制檯,然後點擊此處查看https://developers.facebook.com/tools/debug