2013-04-11 28 views
2

我正在为Facebook创建框架应用程序。 下面的代码工作对我好:Facebook api只为我工作

function changeToHome() { 
    try { 
    var time = new Date(); 
    FB.api("/me", {fields: "id,first_name,last_name,picture"}, function(response) 
    { 
     window.location = '#home'; 
     var fname = encodeURIComponent(response.first_name); 
     var lname = encodeURIComponent(response.last_name); 
     var avatar = encodeURIComponent(response.picture.data.url); 
     var u = '?useradd='+response.id+"&fn="+fname+"&ln="+lname+"&p="+avatar+"&t="+time.getTime(); 
     document.getElementById('game_frame').src=('drop.html'+u); 
     $.ajax({ 
      url: 'stat-api.php'+u 
     }).done(function() { 
      //alert("done"); 
     }); 
    }); 
    } catch(ex) { 
     //alert(ex); 
    } 
} 

但如果我尝试测试它trought其他acounts Facebook的API不起作用(我尝试不同的浏览器,得到了相同的结果

+0

是您的应用发布了吗?在您的应用程序正在开发中时,您需要将人员添加到测试人员组中。你可以从https://developers.facebook.com/apps – 2013-04-11 16:53:36

+0

这样做。我有两个测试人员。他们都无法正常使用应用程序。对于他们“回复”是不明确的:( – 2013-04-11 17:02:26

+0

你应该发布你的解决方案作为回应,以便它与SO上其余的解决问题更好地配合。 – 2013-04-17 13:36:04

回答

0

尝试启用。 (或禁用)沙盒模式。

+0

试过了,结果相同。 – 2013-04-12 09:54:29

0

解决了!它并没有验证我的应用程序!这是一个原因。

纳入window.fbAsyncInit如下因素=函数(){...}

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
    //var uid = response.authResponse.userID; //FACEBOOK_ID 
    //var accessToken = response.authResponse.accessToken;/ //ACCESS TOKEN 
    if (response.authResponse) { 
     // logged in and connected user, someone you know. 
     // YOUR CODE HERE 
      changeToHome() 
    } 
    }else { 
     attemptLogin(); 
    } 
    }); 

function attemptLogin(){ 
    FB.login(function(response) { 
     if (response.authResponse) { 
       // YOUR CODE HERE 
       changeToHome() 
     } else { 
      //if user didn't logged in or didn't authorize your application 
     } 
    }, {scope: 'offline_access,publish_stream,manage_pages,publish_actions,user_games_activity'}); //YOUR PERMISSION 
}