I need help with parsing of JSON feed text returned from Twitter. I need to access, and apply style tags to the link, created_date, and other info. Any hints on how to accomplish this? Thanks in advance
相关问题
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
It'd be much easier to parse on the server-side, but I'm guessing you are doing the site entirely client-side?
sample Javascript:
So with Twitter, there are a many levels of encapsulation, so you need to adjust accordingly. For example, for getting your followers, you'll have something like this:
[{"statuses_count":527,"profile_use_background_image":true, ....
....
,"status":{"place":null,"retweeted_status": {"place":null,"coordinates":null,"retweet_count":"100+","truncated":false,"text":"BLAHBLAHBLAH" .....
So this is just showing index 0. If you wanted to return the text of your first follower's most recent tweet (person who most recently followed you), you'd have to use javascript like this. In this example, the tweet is a retweet (to show use of encapsulation):
POW
First results on google:
Ralph Whitbeck - Blog - Pulling twitter updates with JSON and jQuery. Code below:
And the html:
Another example. Fetching tweets with jQuery and the Twitter JSON API. Reproducing below:
There's a good reason to access the Twitter API from the client-side instead of the server side. If you are accessing their API on the server side with PHP, the server's IP may be rate-limited by Twitter. Furthermore, it seems that Twitter may not have published rate limits.
Using the REST API won't help, as the limit is too low to develop a site for a unknown count (potentially large number) of users. This is not scalable.
Using JavaScript it may be easier to have the client request the data instead.
It would be possible to OAuth each client and using his/her own API-Limit, but what a headache just for getting some tweets. I think, the generic using is an easier bypassing way.
If you want to convert JSON to HTML, there is a nice template engine: tempo js
Look at $.json, it is made specifically for this. It is an ajax call, that automatically parses the json on return (into an array) to be used in the callback.