2015-05-29 76 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