Javascript 使用jquerymobile框架的facebook

Javascript 使用jquerymobile框架的facebook,javascript,jquery,facebook,facebook-graph-api,jquery-mobile,Javascript,Jquery,Facebook,Facebook Graph Api,Jquery Mobile,我正在尝试实现facebook的基本功能,比如更新facebook个人资料,以及使用jquerymobile框架登录facebook。使用此链接 它适用于HTML5格式。但当我与JqueryMobile集成时,我得到了一个错误,该错误表示未捕获异常:无法调用appendChild方法 我会把代码贴在这里:请看一看,让我知道是什么问题 <body> <script type="text/javascript"> window.fbAsyncInit = function(

我正在尝试实现facebook的基本功能,比如更新facebook个人资料,以及使用jquerymobile框架登录facebook。使用此链接

它适用于HTML5格式。但当我与JqueryMobile集成时,我得到了一个错误,该错误表示未捕获异常:无法调用appendChild方法

我会把代码贴在这里:请看一看,让我知道是什么问题

<body> 
<script type="text/javascript">
window.fbAsyncInit = function() {

                FB.init({appId: 'xxxxxxxxxxxxxx', status: true, cookie: true, xfbml: true});



                /* All the events registered */

                FB.Event.subscribe('auth.login', function(response) {

                    // do something with response

                    login();

                });

                FB.Event.subscribe('auth.logout', function(response) {

                    // do something with response

                    logout();

                });



                FB.getLoginStatus(function(response) {

                    if (response.session) {

                        // logged in and connected user, someone you know

                        login();

                    }

                });

            };

            (function() {

                var e = document.createElement('script');

                e.type = 'text/javascript';

                e.src = document.location.protocol +

                    '//connect.facebook.net/en_US/all.js';

                e.async = true;

                document.getElementById('fb-root').appendChild(e); //i am getting error in the is line

            });



            function login(){

                FB.api('/me', function(response) {

                    document.getElementById('login').style.display = "block";

                    document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";

                });

            }

            function logout(){

                document.getElementById('login').style.display = "none";

            }



            //stream publish method

            function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){

                FB.ui(

                {

                    method: 'stream.publish',

                    message: '',

                    attachment: {

                        name: name,

                        caption: '',

                        description: (description),

                        href: hrefLink

                    },

                    action_links: [

                        { text: hrefTitle, href: hrefLink }

                    ],

                    user_prompt_message: userPrompt

                },

                function(response) {



                });



            }

            function showStream(){

                FB.api('/me', function(response) {

                    //console.log(response.id);

                    streamPublish(response.name, 'Something ', 'hrefTitle', 'http://www.ffff.com', "Share www.ffffff.com");

                });

            }



            function share(){

                var share = {

                    method: 'stream.share',

                    u: 'http://www.fffffff.com'

                };



                FB.ui(share, function(response) { console.log(response); });

            }



            function graphStreamPublish(){

                var body = 'hsdfkjasdkjfadkjf;adlfj';

                FB.api('/me/feed', 'post', { message: body }, function(response) {

                    if (!response || response.error) {

                        alert('Error occured');

                    } else {

                        alert('Post ID: ' + response.id);

                    }

                });

            }



            function fqlQuery(){

                FB.api('/me', function(response) {

                     var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id);

                     query.wait(function(rows) {



                       document.getElementById('name').innerHTML =

                         'Your name: ' + rows[0].name + "<br />" +

                         '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />";

                     });

                });

            }



            function setStatus(){

                status1 = document.getElementById('status').value;

                FB.api(

                  {

                    method: 'status.set',

                    status: status1

                  },

                  function(response) {

                    if (response == 0){

                        alert('Your facebook status not updated. Give Status Update Permission.');

                    }

                    else{

                        alert('Your facebook status updated');

                    }

                  }

                );

            }
            </script>
<div data-role="page">

    <div data-role="header">
        <h1>Foofys-Facebook Page</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <p>you are using foofys facebook app</p>
         <div id="fb-root"></div>
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"> </fb:login-button>



        <p>

            <a href="#" onclick="showStream(); return false;">Publish Wall Post</a> |

           <!-- <a href="#" onclick="share(); return false;">Share With Your Friends</a> | -->

            <a href="#" onclick="graphStreamPublish(); return false;">Publish Stream</a> |

           <!-- <a href="#" onclick="fqlQuery(); return false;">FQL Query Example</a> -->

        </p>



        <textarea id="status" cols="50" rows="5">Write your status here'</textarea>

        <br />

      <!--  <a href="#" onclick="setStatus(); return false;">Status Set Using Legacy Api Call</a> -->



        <br /><br /><br />

        <div id="login" style ="display:none"></div>

        <div id="name"></div>       
    </div><!-- /content -->

    <div data-role="footer">
        <h4>Page Footer</h4>
    </div><!-- /footer -->
</div><!-- /page -->

</body>

window.fbAsyninit=函数(){
init({appId:'xxxxxxxxxxxxx',状态:true,cookie:true,xfbml:true});
/*所有事件都已登记*/
FB.Event.subscribe('auth.login',函数(响应){
//做些有反应的事情
登录();
});
FB.Event.subscribe('auth.logout',函数(响应){
//做些有反应的事情
注销();
});
FB.getLoginStatus(函数(响应){
if(response.session){
//已登录并已连接的用户,您认识的人
登录();
}
});
};
(功能(){
var e=document.createElement('script');
e、 类型='text/javascript';
e、 src=document.location.protocol+
“//connect.facebook.net/en_US/all.js”;
e、 异步=真;
document.getElementById('fb-root').appendChild(e);//我在is行中遇到错误
});
函数登录(){
FB.api('/me',函数(响应){
document.getElementById('login').style.display=“block”;
document.getElementById('login')。innerHTML=response.name+“成功登录!”;
});
}
函数注销(){
document.getElementById('login').style.display=“无”;
}
//流发布方法
函数streamPublish(名称、描述、hrefTitle、hrefLink、userPrompt){
FB.ui(
{
方法:“stream.publish”,
消息:“”,
附件:{
姓名:姓名,,
标题:'',
描述:(描述),
href:hrefLink
},
行动链接:[
{文本:hrefTitle,href:hrefLink}
],
用户提示消息:用户提示
},
功能(响应){
});
}
函数showStream(){
FB.api('/me',函数(响应){
//console.log(response.id);
streamPublish(response.name,'Something','hrefitle','http://www.ffff.com","分享www.ffffff.com";;
});
}
函数共享(){
风险值份额={
方法:“stream.share”,
u:'http://www.fffffff.com'
};
ui(共享,函数(响应){console.log(响应);});
}
函数图StreamPublish(){
变量主体='hsdfkjasdkjfadkjf;adlfj';
api('/me/feed',post',{message:body},函数(响应){
如果(!response | | response.error){
警报(“发生错误”);
}否则{
警报('Post ID:'+response.ID);
}
});
}
函数fqlQuery(){
FB.api('/me',函数(响应){
var query=FB.Data.query('select name,homightry\u location,sex,pic\u square from user where uid={0}',response.id);
query.wait(函数(行){
document.getElementById('name').innerHTML=
“您的姓名:”+行[0]。姓名+“
”+ ''+“
”; }); }); } 函数setStatus(){ status1=document.getElementById('status')。值; FB.api( { 方法:“status.set”, 状态:状态1 }, 功能(响应){ 如果(响应==0){ 警报('您的facebook状态未更新。请授予状态更新权限'); } 否则{ 警报(“您的facebook状态已更新”); } } ); } Foofys Facebook页面 您正在使用foofys facebook应用程序

| |

在这里写下你的状态



页脚

我无法理解代码中发生了什么,顺便说一句,我刚刚指出了错误的确切位置。

JQM和FB api的诀窍是使用graph api。也就是说,不要使用简单的javascript FB包装器,因为它们在暴露于JQM的页面处理时是不稳定的——相反,只需使用新的graph/restapi,检查并避免FB核心和您的e集的多个init。比如说

function updateUserInfo(uid, accessToken) {

    var uri = "https://graph.facebook.com/" + uid;
    console.log("About to call FP.api with URI " + uri);    

    $.ajax({
                type: "GET",
                url: "https://graph.facebook.com/" + uid,
                dataType: "json",
                success: 
                    (function (response) {
                        console.log("About to call check profile ...");
                        $("#p_name").val(response.name);
                        $("#email").val(response.email);
                        $("#fb_id").val(response.id);
                        $.ajax({
                            type: "POST",
                            url: "/check_profile",
                            cache: false,
                            data: {fb_id: response.id},
                            success: onCheckSuccess,
                            error: onError
                        });
                        console.log("FB id: " + response.id);                     
                    }),
                error: onError
         });

JQM和fbapi的诀窍是使用graphapi。也就是说,不要使用简单的javascript FB包装器,因为它们在暴露于JQM的页面处理时是不稳定的——相反,只需使用新的graph/restapi,检查并避免FB核心和您的e集的多个init。比如说

function updateUserInfo(uid, accessToken) {

    var uri = "https://graph.facebook.com/" + uid;
    console.log("About to call FP.api with URI " + uri);    

    $.ajax({
                type: "GET",
                url: "https://graph.facebook.com/" + uid,
                dataType: "json",
                success: 
                    (function (response) {
                        console.log("About to call check profile ...");
                        $("#p_name").val(response.name);
                        $("#email").val(response.email);
                        $("#fb_id").val(response.id);
                        $.ajax({
                            type: "POST",
                            url: "/check_profile",
                            cache: false,
                            data: {fb_id: response.id},
                            success: onCheckSuccess,
                            error: onError
                        });
                        console.log("FB id: " + response.id);                     
                    }),
                error: onError
         });

您能否验证
document.getElementBy