通过jquery发布多个facebook帖子

时间:2015-07-02 07:42:03

标签: javascript php jquery angularjs facebook

我正在尝试使用facebook post在网页上发布多个jQuery。到目前为止,我已成功发布facebook post但无法发布另一个<div id="fb-root"> </div><script> (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3"; fjs.parentNode.insertBefore(js, fjs); } (document, 'script', 'facebook-jssdk')); </script> <div class="fb-post" data-href="https://www.facebook.com/ClashofClans/posts/1104473549576967:0" data-width="500"> <div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/ClashofClans/posts/1104473549576967:0"> <p>The update is finally here!!! Maintenance will start soon! Read all that&#039;s new: http://supr.cl/UpdateNotes </p> Posted by <a href="https://www.facebook.com/ClashofClans">Clash of Clans</a> on&nbsp; <a href="https://www.facebook.com/ClashofClans/post/1104473549576967:0">Wednesday, July 1, 2015</a> </blockquote> </div> </div>

发生了什么事?

facebook post embed url是

URL

当我将此DIV直接附加到facebook post时,它会调用iframe,然后在DOM上完成Iframe个数据绑定。它工作得很好,但下次Invalid App Id: Must be a number or numeric string representing the application id.没有加载到DOM上。在控制台第一次发现APP错误,即AppId。我尝试了正确的$("input").blur(function () { $('div').html($(this).val()); //$(this).val() is facebook post URL shown above }) ,但没有成功。以下是我到目前为止所尝试的代码

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET filename=%~1 
echo !filename!
ENDLOCAL

有人会建议我这样做的正确方法吗?

1 个答案:

答案 0 :(得分:0)

使用以下代码。它会影响代码的加载时间。答案是使用此源Working with asynchronously loaded javascript创建的。如果愿意,可以将getLoginStatus调用包装在循环中。

    <!DOCTYPE HTML>
<html>
    <head>
        <title></title>
        <script src="jquery-1.11.1.min.js"></script>
    </head>
    <body>
        <input type="text" id="message" />
        <input type="button" id="send" value="Send" />
    <script>
        $(document).ready(function(){
            function facebookReady() {
                FB.init({
                    appId      : '1521775134725984',
                    xfbml      : true,
                    status   : true,
                    cookie     : true,
                    version    : 'v2.1'
                });
                $(document).trigger("facebook:ready");
            }

            if(window.FB) {
                facebookReady();
            } else {
                window.fbAsyncInit = facebookReady;
            }
        });

        $(document).on("facebook:ready", function() {

            $("#send").on("click", function() {
                FB.getLoginStatus(function(response) {
                    if (response.status === 'connected') {
                        var body = $("#message").val();
                        FB.api('/me/feed', 'post', { message: body }, function(response) {
                            if (!response || response.error) {
                                alert('Error occured');
                            } else {
                                alert('Post ID: ' + response.id);
                            }
                        });
                    }
                    else {
                        FB.login(function(){
                        }, {scope: 'publish_actions'});
                    }
                });
            });
        });

    (function(d, s, id){
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>
    </body>
</html>