08-01-2014 09:21 AM - edited 08-01-2014 09:23 AM
Hi, I just recently worked on pulling statuses from Facebook. Here's what I did:
Make an HTTP connection to the public Facebook feed. You can grab a public feed by using a url similar to
https://www.facebook.com/feeds/page.php?id=<feed id here>&format=json
Once you've made the connection, make sure you parse the return string as UTF-8:
byte bytes = IOUtilities.streamToBytes(conn.openInputStream()); StringBuffer buff = new StringBuffer(new String(bytes, "UTF-8"));
One you've parsed the data as UTF-8 you can do something similar to the below code:
root = new JSONObject(output); JSONArray entries = root.getJSONArray("entries"); JSONObject entry_obj1 = entries.getJSONObject(0); JSONObject entry_obj2 = entries.getJSONObject(1); JSONObject entry_obj3 = entries.getJSONObject(2); String entry1 = TextUtils.unescapeHTML(entry_obj1.getString("title
").trim(),0); String entry2 = TextUtils.unescapeHTML(entry_obj2.getString("title ").trim(),0); String entry3 = TextUtils.unescapeHTML(entry_obj3.getString("title ").trim(),0);
In that code, I'm grabbing the array of entries from the JSON structure, and then grabbing the titles of the last 3 posts.
As far as Twitter goes, I actually gave up once I found out that you need to be authenticated in order to use their API. I couldn't get a twitter sdk for Java imported into Blackberry correctly so I gave up.