使用JavaScript SDK创建Facebook活动?

时间:2011-11-21 11:10:15

标签: facebook-javascript-sdk

我使用Javascript SDK创建了一个javascript事件,它没有错误,但它不会创建事件。

Welcome to our New Facebook App <span id='fbinfo'><fb:name uid='loggedinuser' useyou='false'></fb:name></span>
<div id='fb-root'></div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type='text/javascript'>

    var fbuserid, fbtoken;
    var appid = "265435383502778";
    var loggedin = false;
    $(document).ready(function() {
        //loginFB();
    });

    FB.init({appId: appid, status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('auth.sessionChange', function(response) {
            if (response.session) {
                var session = FB.getSession();
                fbtoken = session.access_token;
                fbuserid = session.uid;
            }
    });

    FB.getLoginStatus(function(response) {
        if (response.session) {
            var session = FB.getSession();
            fbtoken = session.access_token;
            fbuserid = session.uid;
        }
        else{
            loginFB();
        }
    });

    function loginFB() {
        FB.login(function(response) {
            if (response.session) {
                var session = FB.getSession();
                fbtoken = session.access_token;
                fbuserid = session.uid;
            }
        }, {perms:'create_event'});
    }

    function logoutFB() {
        FB.logout(function(response) {
            // user is now logged out
        });
    }
function createEvent(name, startTime, endTime, location, description) {
    var eventData = {
        "access_token": fbtoken,
        "start_time" : startTime,
        "end_time":endTime,
        "location" : location,
        "name" : name,
        "description":description,
        "privacy":"OPEN"
    }
    FB.api("/me/events",'post',eventData,function(response){
        if(response.id){
            alert("We have successfully created a Facebook event with ID: "+response.id);
        }
            return false;

    })
}

function createMyEvent(){
    var name = "My Amazing Event";
    var startTime = "11/29/2011 12:00 PM";
    var endTime = "11/29/2011 06:00 PM";
    var location = "Dhaka";
    var description = "It will be freaking awesome";
    createEvent(name, startTime,endTime, location, description);
}
</script>

<label>
<input type="submit" name="Submit" value="Submit" onClick="createMyEvent();">
</label>

有什么问题?

1 个答案:

答案 0 :(得分:0)

我知道这个问题已经过时了。但是,如果其他人正在寻找答案,这可能不是100%的解决方案,但它创造了一个事件。 Facebook不接受startTimeendTime格式。因此,如果您删除时间12:00 PM06:00 PM,则会有效。只需要搜索Facebook如何格式化他们的日期时间,你就可以匹配变量。