显示Facebook,Instagram和其他社交网站等更新

时间:2016-06-02 10:47:58

标签: jquery html mysql ajax jsp

我正在开发一个项目,用户可以在其中共享图像,并对其进行评论,因此所有数据都将保存在数据库中 我想显示用户名,图片,没有。喜欢,没有。对主页的评论。 我已经使用了jQuery的append标记并将其放在jsp while循环中,以将listitems附加到无序列表中。 因此,当我取消时,我已经成功地为不同的列表项显示了不同的图像。喜欢并在listitem中根据其Id显示在span标签中,该数字会被添加到所有列表项的span标签中。

当我们打开主页时,有人可以帮助我或建议我以新的方式显示Facebook和Instagram等更新...并在我点击用户名或图标或评论图标时做出相应的响应。 这是完成提取和显示内容的脚本部分。

    <script>
    var image_id,image_src,nameHead, noOfLikes, likeIcon;

    $(document).ready(function() {

        <%
        Statement st = db.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rs = st.executeQuery("Select * from followings_table where user_id='"+Integer.parseInt(session.getAttribute("user_id").toString())+"'");
        Statement statement_gallery = db.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet_gallery = statement_gallery.executeQuery("Select * from image_table where category='usual pic' ORDER BY datetime DESC");
        ArrayList<Integer> list = new ArrayList<Integer>();
        while(rs.next()) {
            list.add(rs.getInt("user_two"));
            System.out.println(rs.getInt("user_two"));
        }
        int flag = 0;
    while(resultSet_gallery.next()) {
            System.out.println("Second"+resultSet_gallery.getInt("user_id"));
        if(list.contains(resultSet_gallery.getInt("user_id"))){
            flag=1;
        %> 
                image_id="<%=resultSet_gallery.getInt("image_id")%>";
                image_src="data:image/jpg;base64,<%=resultSet_gallery.getString("image")%>";
                nameHead="<%=resultSet_gallery.getString("username")%>";
                $( "#updateCol" ).append('<div class="w3-container w3-card-2 w3-white w3-round w3-margin-left w3-margin-right w3-margin-bottom"><br><img src="" alt="Avatar" class="w3-left w3-circle w3-margin-right" style="width:60px"><span class="w3-right w3-opacity">1 min</span><h4 id="nameHead"></h4><br><img id="demo_img" src="" style="width:100%;"><hr class="w3-clear"><div class="w3-container w3-white"><div class="w3-padding-xlarge w3-left"><a><i class="material-icons color-tuna" style="cursor: pointer; pointer-events: none;" id="like" onclick="like()">favorite_border</i><span class="w3-badge bg-valencia" id="no_of_likes" onclick="getLikeList()">0</span></a></div><div class="w3-padding-xlarge w3-left"><a><i class="material-icons color-tuna"style="cursor: pointer; pointer-events: none;" id="comment" >comment</i></a><span class="w3-badge bg-valencia" id="no_of_comments" onclick="getCommentList()">0</span></div></div></div>'); 

            getDetails();
      <%   
        }}if(flag==0) {%>
        $( "#updateCol" ).append('<div class="w3-container w3-card-2 w3-white w3-round w3-margin-left w3-margin-right w3-margin-bottom"><br><h4>Follow some users to get started.</h4><br><h4>All the updates will then appear in this section</h4><br></div>');
        <%}

        %>

    });
    function getDetails() {
        $("#nameHead").text(nameHead);
        document.getElementById("demo_img").setAttribute("id", image_id);
        document.getElementById(image_id).setAttribute("src", image_src);
        liketoggle("likeNumber.jsp?imageId="+image_id, cfunction);
    }
    function cfunction(xhttp) {
        var res = xhttp.responseText;
        var arr = res.split(';');
        if(arr[0]=='0') {
            noOfLikes = 'arr[0]';
            likeIcon="favorite_border";
        }
        else {
            noOfLikes = 'arr[0]';
        }
        return true;
    }
    function liketoggle(url, cfunc) {
        var xhttp;
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        } else {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.onreadystatechange = function() {
            if (xhttp.readyState === 4 && xhttp.status === 200) {
                cfunc(xhttp);
            }else if(xhttp.status === 404) {
                alert("request not completed");
            }
        };
        xhttp.open("GET", url, true);
        xhttp.send();
    }

        </script>
<div class="w3-col m7" id="updateCol">


    <!-- End Middle Column -->
    </div>

1 个答案:

答案 0 :(得分:0)

您可以通过一点点PHP和FQL(Facebook查询语言)获取喜欢的总数和共享数量。

您不必使用Facebook SDK或API,这个技巧适用于Facebook页面以及任何具有类似按钮或已在Facebook上共享的外部网页。

function facebook_count($url){

  // Query in FQL
        $fql  = "SELECT like_count ";
        $fql .= " FROM link_stat WHERE url = '$url'";

        $fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);

        // Facebook Response is in JSON
        $response = file_get_contents($fqlURL);
        return json_decode($response);

    }

    $fb = facebook_count('https://www.facebook.com/digital.inspiration');

    // facebook like count
    echo $fb[0]->like_count;