- Post on your/ your friend's facebook wall,
- Go to restfb api and download its libraries..
- Extract restfb-verno.jar and place in eclipse's build path,
- Using java program(bottom of the post) you can post/get info from your facebook profile, but first u need to get access token..
- Login using fb username n password...
- Go to https://developers.facebook.com/apps and create a new app
- After creating ur app, in the left side pane u can find settings, choose that and go to Auth dialog,
- choose default activity privacy to friends or public,
- In Authenticated Referrals, mention user and friend permissions to public_actions, user_status, friends_status, user_photos..etc.., and set extended settings to publish_stream, read_stream, photo_upload, read_mailbox etc..,(based on your requirement whether u want to GET info or POST info).
- save all the changes and then choose use GRAPH API explorer in the left side pane related links.
- Now new page with graph API explorer will open, click on Get Access Token,
- new window opens where u have to set User data permissions(choose user_photos, user_status..etc), Friends data permissions(friends_photo, friends_status, etc) and Extended permissions(publish_stream, read_stream,upload_photos, offline_status etc). click Get Access Token and then allow this app to use ur related data.
- An access token will be generated, u have to use this in the program to GET/POST data(based on the extended permissions u have set).
- Copy this access token and use this to post a message on your facebook wall
import java.io.*;
import com.restfb.*;
import com.restfb.types.*;
import com.restfb.util.*;
public class FacebookTest
{
public static void main(String args[])
{
FacebookClient facebookClient = new DefaultFacebookClient(<ur access token>);
// It's also possible to create a client that can only access
// publicly-visible data - no access token required.
// Note that many of the examples below will not work unless you supply an access token!
User user = facebookClient.fetchObject("me", User.class);
System.out.println("User name: " + user.getName());
System.out.println("Last name: " + user.getLastName());
String connection = "me/feed";
FacebookType publishMessageResponse =
facebookClient.publish(connection, FacebookType.class,
Parameter.with("message", "helo ..:)"));
FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,BinaryAttachment.with("holiMan.jpg",FacebookTest.class.getResourceAsStream("holiMan.jpg")),Parameter.with("message", "The HOLI MAN")); \\should be in same directory of source code, in this code in bin directory of eclipse IDE
//System.out.println("Published message ID: " + publishMessageResponse.getId());
System.out.println("Success");
}
}