2015-05-29 77 views
0

我正在使用facebook4j在我的Facebook墙上发送帖子。在这样做的时候,我面临着一个错误。在我的控制台中显示的错误是运行我的代码时。我检查了我的appid,appSecretaccesstoken这些值也是正确的。使用java集成Facebook

这里是我用来发送消息的代码:

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(); 
     } 
    } 

我提示以下错误:在我的控制台:

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}} 
', [email protected]35678, 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) 

有人能指出我的错误?

+0

您必须直接从Facebook请求访问令牌... – MadProgrammer

+0

您好,我遇到同样的错误,您是否发现了facebook4j的解决方案? – jNick

回答

0

这是因为您可能使用的访问令牌无效或者您在调用post方法时没有使用访问令牌。要获得有效的活动访问令牌,只需使用活动会话即可生成。

​​

使用上述生成的访问令牌,您可以使用图形API调用在墙上张贴。

注意:还请确保您已经提到了您创建的Facebook应用程序中的发布权限。

+1

facebook4j没有'Session'对象 – Evvo