2013-11-01 156 views
1

我正在嘗試使用Facebook4J開發Facebook API。將facebook的access_token作爲流程獲得成功。使用Facebook4j Facebook api請求失敗

@RequestMapping(value="biztopia.facebook.redirectLogin.do") 
public void redirectLogin(ModelMap model, HttpServletRequest request, HttpServletResponse response, HttpSession session) { 

    String code = request.getParameter("code");  
    Facebook facebook = (Facebook) request.getSession().getAttribute("facebook"); 
    String oauthCode = request.getParameter("code"); 

    try { 
     facebook.getOAuthAccessToken(oauthCode);    
     AccessToken token = facebook.getOAuthAccessToken();    
     response.sendRedirect("biztopia.facebook.requestUserInfo.do"); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }   
} 


@RequestMapping(value="biztopia.facebook.requestUserInfo.do") 
public void requestUserInfo(ModelMap model, HttpServletRequest request, HttpServletResponse response, HttpSession session) { 

    Facebook facebook = (Facebook) request.getSession().getAttribute("facebook");    
    try {   
     User user = facebook.getMe(); 
    }catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

收到EXCETION消息作爲流

FacebookException {的StatusCode = 400,響應=的HttpResponse {的StatusCode = 400,responseAsString ='{ 「錯誤」:{ 「消息」:「從服務器API調用需要一個appsecret_proof參數「,」type「:」GraphMethodException「,」code「:100}} ',[email protected]46f4515,streamConsumed = true},errorType ='GraphMethodException ',errorMessage ='來自服務器的API調用需要appsecret_proof參數',errorCode = 100,errorSubcode = -1}在facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189) 噸facebook4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) 在facebook4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93) 在facebook4j.FacebookImpl.get(FacebookImpl.java:2431) 在facebook4j.FacebookImpl.getMe(FacebookImpl.java:105) 在facebook4j.FacebookImpl.getMe(FacebookImpl.java:101) 在biztopia.facebook.web.FacebookController.requestUserInfo(FacebookController.java:292)

回答

1

我找到了解決方案。 這是在呼叫API爲「http://graph.facebook.com/me?access_token= {ACCESS_TOKEN值} $ appsecret_proof = {appsecret_proof值}追加appsecret_proof參數。

如果你沒有想追加appsecret_proof參數則可以更改設置爲不使用appsecret_proof paameter在您的應用程序管理 管理站點菜單設置>高級>需要AppSecret Proof for Server API調用 - >設置爲禁用。