我正在尝试使用 Facebook4J 开发 Facebook API。从 facebook 获取 access_token 作为流程是成功的。
@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();
}
}
收到异常消息作为流
FacebookException{statusCode=400, response=HttpResponse{statusCode=400, responseAsString='{"error":{"message":"来自服务器的 API 调用需要 appsecret_proof 参数","type":"GraphMethodException","code" :100}} ', is=sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@446f4515, 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)