박동화
박동화

Reputation: 21

Fail when Facebook api request using Facebook4j

I am trying to developing Facebook API using Facebook4J. It is success to get access_token from facebook as flow.

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

Recieved excetion message as flow

FacebookException{statusCode=400, response=HttpResponse{statusCode=400, responseAsString='{"error":{"message":"API calls from the server require an appsecret_proof argument","type":"GraphMethodException","code":100}} ', is=sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@446f4515, streamConsumed=true}, errorType='GraphMethodException', errorMessage='API calls from the server require an appsecret_proof argument', errorCode=100, errorSubcode=-1} at facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189) at facebook4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) at facebook4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93) at facebook4j.FacebookImpl.get(FacebookImpl.java:2431) at facebook4j.FacebookImpl.getMe(FacebookImpl.java:105) at facebook4j.FacebookImpl.getMe(FacebookImpl.java:101) at biztopia.facebook.web.FacebookController.requestUserInfo(FacebookController.java:292)

Upvotes: 1

Views: 2083

Answers (1)

박동화
박동화

Reputation: 21

I found the solutions. That is append appsecret_proof parameter at call API as "http://graph.facebook.com/me?access_token={access_token value}$appsecret_proof={appsecret_proof value}.

If you are no want append appsecret_proof parameter then you can change set to no use appsecret_proof paameter on your app management site. The management site menu is setting>advanced>Require AppSecret Proof for Server API calls -> set to disabled.

Upvotes: 1

Related Questions