Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 10
Registered: ‎04-05-2014
My Device: BB Alpha Device
My Carrier: Airtel

How to share data on Facebook and twitter

How to share data on Facebook and twitter. How their sdk we can implement
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to share data on Facebook and twitter

Have you searched this forum?  Try the search box you will find near the top right.

Highlighted
Developer
Posts: 40
Registered: ‎06-04-2014
My Device: Bold 9900

Re: How to share data on Facebook and twitter

[ Edited ]

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.