I am using a facebook4j to send a post on my Facebook wall. While doing so, I am facing an error. The error is showing in my console is when running my code. I have checked my appid
, appSecret
and accesstoken
values which are also correct.
Here is the code I am using to send the message:
public static void sendMessage(){
Facebook facebook = new FacebookFactory().getInstance();
String appId = "XXXXX";
String appSecret = "XXXXXXXXXXX";
facebook.setOAuthAppId(appId, appSecret);
String commaSeparetedPermissions ="user_friends,user_groups,user_photos,user_videos,user_birthday,user_status,user_likes,user_activities,user_location";
facebook.setOAuthPermissions(commaSeparetedPermissions);
String accessToken = "XXXXXXXXXXXXXX";
facebook.setOAuthAccessToken(new AccessToken(accessToken, null));
try {
facebook.postStatusMessage("Hello World from Facebook4J From Java Programming....");
} catch (FacebookException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am getting the below error in my console:
FacebookException [statusCode=400, response=HttpResponse{statusCode=400, responseAsString='{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
', is=sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@335678, streamConsumed=true}, errorType=OAuthException, errorMessage=An active access token must be used to query information about the current user., errorCode=2500]
at facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
Can someone point out my error?