Social Java:
Social Application development using Java
Overview
TinyFBClient- A very small Facebook Java client.
TinyFBTaglib - Tags that can be added to JSP pages to call the Facebook API.
What is TinyFBTaglib?
TinyFBTaglib is a Tag Library for calling Facebook API functions in a JSP Page.
Initial tags are getFriends,makeFriendList,senfNotificatons,publishUserActionFeed
Examples
Shout Out Facebook App - demonstrates what the tags can do. Give it a try!
Shout Out App running in Web Page - Uses Yahoo Carousel Widget to display friends on page.
Example - Page that demonstrates tags and usage.
Support
Social Java: Facebook Group Support and general questions on Java for Facebook.
Setting up and using TinyFBTaglib
(See Next Section for instructions when using TinyFBTaglib on GoogleAppEngine)
- Get TinyFBTagLib Jar file (includes TinyFBClient):
tinyfbtaglib04152009.jar
- Get other required jar files:
commons-codec-1.3.jar,
jersey-bundle-1.0.2.jar,
json-1.0.jar,
jsr311-api-1.0.jar (You should check the web for updates to jars)
- Get tiny.tld
- Place jar files in your WEB-INF/lib/ directory
- Put tiny.tld where your JSPs are.
For questions on the next 2 steps see Facebook Getting Started Page
- create an app on facebook to get API KEY and API SECRET
- Make tinycanvas.jsp your callback url (use the full location on your server, for example http://www.[YOUR SERVER NAME].com/tinycanvas.jsp)
- Download tinycanvas.jsp
- Download tinycanvasapp.jsp
- Modify your copy of tinycanvas.jsp by replacing YOUR_API_KEY and YOUR_API_SECRET with the values received from Facebook
- put tinycanvas.jsp in your jsp directory
- put tinycanvasapp.jsp in your jsp directory
- Try the application on Facebook!
Setting up and using TinyFBTaglib on GoogleAppEngine
- Get TinyFBTagLib Jar file (includes TinyFBClient):
tinyfbtaglib04152009.jar
- Get other required jar files:
jersey-client-1.0.2.jar,
jersey-core-1.0.2.jar,
json-1.0.jar,
jsr311-api-1.0.jar
- Get tiny.tld
- Place jar files in your WEB-INF/lib/ directory. Using Eclipse plugin these will be under war folder
- Put tiny.tld where your JSPs are. In war folder of project.
Create an application on Google AppEngine
Get the Url of what your application will be. Something like http://MYAPPLICATION.appspot.com
In this example, MYAPPLICATION, is the application identifier
For questions on the next 2 steps see Facebook Getting Started Page
- create an app on facebook to get API KEY and API SECRET
- Make the application you create in GAE your callback url. In our examlple, http://MYAPPLICATION.appspot.com
- Download tinycanvas.jsp
- Download tinycanvasapp.jsp
- Modify your copy of tinycanvas.jsp by replacing YOUR_API_KEY and YOUR_API_SECRET with the values received from Facebook
- put tinycanvas.jsp where your JSPs are. War folder of project.
- put tinycanvasapp.jsp in your jsp directory. War folder of project.
- Modify appengine-web.xml to include your application id. In our example, MYAPPLICATION.
- Deploy to Google. This is easy in Eclipse. Hit the Google AppEngine button on toolbar.
- Try the application on Facebook!
Usage - examples
Get Friends of Logged on User by specifying empty id
<fbtag:getFriends id="" />
Get Friends of Carmen Delessio by specifying id
<fbtag:getFriends id="725391757" />
Get Friends who are app users
<fbtag:getFriends id="" appUsers="true" />
Get Friends List of logged on user
<fbtag:getFriends id="" lists="true" />
Get Friends logged on user. Return Common fields: uid, first_name, last_name, pic_square, profile_url
<fbtag:getFriends id="" commonFields="true" />
Show Friend Selector. Note this can be styled. See Shout Out Example that turns this into a Carousel Widget
<fbtag:getFriends id="" selector="true" startTag="<p>" endTag="</p>"/>
Send Notification to self
<fbtag:sendNotifications toIds="" notification="notification to self" />
Send Notification to self with optional url and linkText
<fbtag:sendNotifications toIds="" notification="Sent from a tag!" url="http://www.brightkeep.com" linkText="Go to
BrightKeep" />
Publish a Feed
<fb:PublishUserActionFeed templateBundleId="981----5808" />
Publish A Feed with Optional imageHref and imageSrc
<fb:PublishUserActionFeed templateBundleId="981----5808" imageHref="http://apps.facebook.com/friendshoutout"
imageSrc="http://images.brightkeep.s3.amazonaws.com/bullhorn.jpg" />
Note: Create templateBundleId in FeedConsole
What is TinyFBClient?
TinyFBClient is a Java Client for talking to Facebook Rest Server.
To make a Facebook API call, you populate a TreeMap with required parameters.
You can then use the call method or getResponse method.
Call will return a String of output from Facebook's response.
GetResponse will return a ClientResponse. (com.sun.jersey.api.client.ClientResponse)
What is TinyFBClientExample?
TinyClientExample is a Facebook Application that illustrates the use of the
Java TinyFBClient to communicate with Facebook's REST Server.
The app sends a notification,
publishes to the newsFeed,
and gets a list of friends
Add the Application
Source Code and JavaDoc:
TinyFBClient.java and TinyFBClientExample.jsp are on github
TinyFBClient.java JavaDoc
Usage - Examples:
1. Call friends.get with a specific user id. Does not require a Facebook session.
TinyFBClient fb = new TinyFBClient("APPLICATION ID","SECRET KEY");
TreeMap
tm.put("uid", "725391757");
String friendList = fb.call("friends.get", tm);
2. Call friends.get for a logged on user. Requires a Facebook session.
TinyFBClient fb = new TinyFBClient(
"Application ID",
"SecretKey",
sessionKey);
TreeMap
tm.put("uid", ""); // empty String for logged on user
currentUsersFriends = fb.call("friends.get",tm);
3. JSON is default format for returned String. Set TinyFBClient format to XML.
TinyFBClient fb = new TinyFBClient(
"Application ID",
"SecretKey",
sessionKey);
fb.setFormat("XML");
TreeMap
tm.put("uid", ""); // empty String for logged on user
currentUsersFriends = fb.call("friends.get",tm);
4. Send Notification, return ClientResponse
int status;
ClientResponse c;
tm.clear();
tm.put("to_ids", ""); // to logged on user
tm.put("notification", "Thanks for trying TinyClientExample.");
c = fb.getResponse("notifications.send", tm);
status = c.getStatus(); //200 for good response.
About Random Friend:
About the Random Friend Application Facebook and Facebook Connect Application.
Source Code
README
Java Development info from previous homepage
Sample code and explanations
About Carmen
Carmen Delessio's Resume
Social Java: The Blog Updates on coding progress. Comments welcome.