Question

Hi I am new to Twitpic API. I want to make a call to TwitPic API

http://api.twitpic.com/2/tags/show.xml?tag=" + searchq + "&page=1"

I want to do it using AJAX my current code is as below:

<script type="text/javascript">
    var searchq = 'first';
    $(document).ready(function () {
        $("#btnGetData").click(function () {
                $.ajax({
                type: "GET",
                /* define url of xml file to parse */
                url: "http://api.twitpic.com/2/tags/show.xml?tag=" + searchq + "&page=1",
                /* assign it a data type */
                dataType: "xml",
                /* state name of function to run if file is successfully parsed */
                success: parseXml
            });
        });
    });
    function parseXml(xml)
    /* this is where the xml file is parsed and converted into a HTML output */
    {

        //for each item node in the xml file
        $(xml).find("image").each(function () {
            //print the following html, inserting the relevant data within the nodes of item
            //this is the heading
            $("#tweets").append($(this).attr("id") + "<br />");
            $("#tweets").append($(this).attr("short_id") + "<br />");
            $("#tweets").append($(this).attr("type") + "<br />");
            $("#tweets").append($(this).attr("timestamp") + "<br />");

        });
        //end for each 
        //end function
    }

</script>

And my HTML looks like below:

<body>
<input id="btnGetData" type="button" value="Twitter Get Tweets" />
<div id="tweets">
</div>

I am not getting any error but the call to this API is not happening. I want to parse XML returned from this API. If you can provide me demo code for parsing Twitpic API XML it would be really great help.

Thanks in Advance; Abhishek A. Sharma

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top