Facebook post to Wall Javascript HTML5

Facebook post to Wall Javascript HTML5

本文关键字:Javascript HTML5 Wall to post Facebook      更新时间:2023-09-26

我想看看从HTML5游戏发布到Facebook的最佳方式,我需要从我的javascript文件中提取数据才能发布到我尝试添加的Facebook。

FB.init({
    appId: "309749382423000",
    status: true,
    cookie: true
});
function postToFeed() {
    // calling the API ...
    var obj = {
        method: 'feed',
        link: 'https://google.com/',
        picture: 'http://google.com',
        name: ' Run!',
        caption: 'I just got a highscore of' + points2,
        description: 'Try to beat my score!.'
    };
    function callback(response) {
        document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }
    FB.ui(obj, callback);
}

这是添加到我的索引文件中的,它不会提取每次玩游戏时都会更改的var点2,所以我想在html5 canvus 中尝试将Post添加到facebook时得到一些帮助

EDIT:想要发布完整的代码。发布到facebook是有效的,但游戏是HTML5,所以javscript文件在游戏中继续运行,上面的代码在我的索引文件中,它不会循环,所以它加载但不会运行。将"points2"var拉到facebook代码中。所以真正的问题将是如何在canvusHTML5游戏中添加facebook帖子。

假设用户已经通过了应用程序的身份验证,请使用:

FB.getLoginStatus( function ( response ) {
    if ( response.authResponse ) {
        FB.api( 
            '/me/feed',
            'post',
            {
                message: '',
                name: 'Run!',
                caption: 'I just got a highscore of ' + points2,
                description: 'Try to beat my score!.',
                link: 'https://google.com/',
                picture: 'https://google.com/pic.png'
            },
            function ( response ) {
                if ( response.id ) {
                    //success
                } else {
                    //failure
                };
            }
        );
    };
} );

相关文章: