来自chrome扩展的Facebook - getLoginStatus失败

时间:2011-06-22 21:57:55

标签: facebook google-chrome facebook-graph-api google-chrome-extension

我正在写一个镀铬扩展程序,它可以与facebook一起工作,但我在开始时失败了:授权

以下代码

<html>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({appId: 'xxx', status: true, cookie: true, xfbml: false});

};
(function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = 'http://connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function() {
     FB.init({appId: 'xxx', status: true, cookie: true, xfbml: true});

         /* All the events registered */
         FB.Event.subscribe('auth.login', function(response) {
             // do something with response
                document.write('Not written out');
             //login();
         });

         FB.Event.subscribe('auth.logout', function(response) {
             // do something with response
        document.write('Not written out');
             //logout();
         });

         arpa = FB.getLoginStatus(function(response) {
        document.write('Not written out');
             if (response.session) 
             {
                 // logged in and connected user, someone you know
            document.write('Not written out');
                 //login();
             }
         else
             { 
                 document.write('Not written out');
             }
         }, true);
document.write(arpa); // writes out - 'undefined'
document.write('This is written out');
     };
</script>
</html>

不起作用,因为FB.getLoginStatus函数似乎没有返回任何内容,也没有调用回调函数,也没有打印出来。

但这不是一个错误的行,因为程序继续并写出“undefined”和最后一个document.write

是什么导致这个?从fb退出也不能解决问题。

1 个答案:

答案 0 :(得分:0)

我不明白上述解决方案。

使用js sdk无法通过Chrome扩展程序进行身份验证。您应该使用Oauth并通过http调用直接连接。

这就是我看到chrome fb应用程序在查看源代码时的用法。这是一个例子:

https://github.com/zuzara/facebook-connect-for-chrome-extension