简体   繁体   中英

How to get json data from javascript file

help, im using tumblr and connect my twitter account, Tumblr gave me this file example: http://titan-theme.tumblr.com/tweets.js

my question is can i get follower_count and screen_name data? if yes how to get it? please help me thanks

If you have only this file you should define *recent_tweets* function. Of cours you need to import tweets.js. For example:

<script>
    var recent_tweets = function(tweets) {
        for(var i=0; i<tweets.length; i++) {
            var tweet = tweets[i];
            var followerCounts = tweet.user.followers_count;
            var screenName = tweet.user.screen_name;
        }
    }   
</script>
<script src="tweets.js"></script>

However, there is no follower_count available.

This is a JSONP file, it needs to be requested via a script tag in order to execute the recent_tweets function that encloses it. Try using the jQuery ajax function.

$.ajax({
  dataType: "jsonp",
  success: function (result) {
    callback(result);
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM