我使用相当基本的设置来使用spring boot和spring social来连接facebook,但是我在日志中收到警告而没有其他细节:
2015-11-01 09:26:34.574 WARN 69742 --- [nio-8181-exec-1] o.s.s.connect.web.ConnectController : Exception while handling OAuth2 callback ((#3) Application does not have the capability to make this API call.). Redirecting to facebook connection status page.
我的控制器:
@Controller
public class UserLoginOauth {
private Facebook facebook;
@Inject
public UserLoginOauth(Facebook facebook) {
this.facebook = facebook;
}
@RequestMapping(value = "/fb")
public String connectFacebook(Model model) {
try {
if (!facebook.isAuthorized()) {
return "redirect:/connect/facebook";
}
} catch (Exception e) {
return "redirect:/connect/facebook";
}
return null;
}
和我的属性文件:
spring.social.facebook.appId=XXX
spring.social.facebook.appSecret=YYY
spring.social.auto_connection_views=true
当我转到我的/ fb网址时,我会通过一个按钮连接到Facebook重定向到http://localhost:8181/connect/facebook
点击该按钮后,系统会调用http://localhost:8181/connect/facebook,然后重定向到https://www.facebook.com/v2.3/dialog/oauth?client_id=WWW,然后再次重定向到http://localhost:8181/connect/facebook?code=ddd&state=GGG
但是这个重定向失败并显示警告消息"处理OAuth2回调时的异常",没有其他信息。
我启用了春季社交日志,并将其放在下面,这有助于它!
2015-11-09 15:07:38.130 DEBUG 14198 --- [nio-8181-exec-3] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/connect/facebook]
2015-11-09 15:07:38.131 DEBUG 14198 --- [nio-8181-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /connect/facebook
2015-11-09 15:07:38.131 DEBUG 14198 --- [nio-8181-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)]
2015-11-09 15:07:38.131 DEBUG 14198 --- [nio-8181-exec-3] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'connectController'
2015-11-09 15:07:38.131 DEBUG 14198 --- [nio-8181-exec-3] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2015-11-09 15:07:38.132 DEBUG 14198 --- [nio-8181-exec-3] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.RedirectView: unnamed; URL [https://www.facebook.com/v2.3/dialog/oauth?client_id=XXX&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8181%2Fconnect%2Ffacebook&state=SSS]] in DispatcherServlet with name 'dispatcherServlet'
2015-11-09 15:07:38.132 DEBUG 14198 --- [nio-8181-exec-3] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2015-11-09 15:07:38.132 DEBUG 14198 --- [nio-8181-exec-3] o.s.orm.jpa.EntityManagerFactoryUtils : Closing JPA EntityManager
2015-11-09 15:07:38.132 DEBUG 14198 --- [nio-8181-exec-3] o.s.web.servlet.DispatcherServlet : Successfully completed request
2015-11-09 15:07:42.007 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/connect/facebook]
2015-11-09 15:07:42.007 DEBUG 14198 --- [nio-8181-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /connect/facebook
2015-11-09 15:07:42.008 DEBUG 14198 --- [nio-8181-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)]
2015-11-09 15:07:42.008 DEBUG 14198 --- [nio-8181-exec-4] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'connectController'
2015-11-09 15:07:42.008 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/connect/facebook] is: -1
2015-11-09 15:07:42.008 DEBUG 14198 --- [nio-8181-exec-4] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2015-11-09 15:07:42.009 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Created POST request for "https://graph.facebook.com/v2.3/oauth/access_token"
2015-11-09 15:07:42.009 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Setting request Accept header to [application/x-www-form-urlencoded, multipart/form-data, application/json, application/*+json]
2015-11-09 15:07:42.009 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Writing [{client_id=[AAA], client_secret=[BBB], code=[CCC], redirect_uri=[http://localhost:8181/connect/facebook], grant_type=[authorization_code]}] using [org.springframework.http.converter.FormHttpMessageConverter@16aa8eeb]
2015-11-09 15:07:42.554 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : POST request for "https://graph.facebook.com/v2.3/oauth/access_token" resulted in 200 (OK)
2015-11-09 15:07:42.555 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Reading [interface java.util.Map] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@53ab366e]
2015-11-09 15:07:42.559 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Created GET request for "https://graph.facebook.com/v2.3/me?fields=id%2Cabout%2Cage_range%2Caddress%2Cbio%2Cbirthday%2Ccontext%2Ccover%2Ccurrency%2Cdevices%2Ceducation%2Cemail%2Cfavorite_athletes%2Cfavorite_teams%2Cfirst_name%2Cgender%2Chometown%2Cinspirational_people%2Cinstalled%2Cinstall_type%2Cis_verified%2Clanguages%2Clast_name%2Clink%2Clocale%2Clocation%2Cmeeting_for%2Cmiddle_name%2Cname%2Cname_format%2Cpolitical%2Cquotes%2Cpayment_pricepoints%2Crelationship_status%2Creligion%2Csecurity_settings%2Csignificant_other%2Csports%2Ctest_group%2Ctimezone%2Cthird_party_id%2Cupdated_time%2Cverified%2Cvideo_upload_limits%2Cviewer_can_send_gift%2Cwebsite%2Cwork"
2015-11-09 15:07:42.584 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : Setting request Accept header to [application/json, application/*+json]
2015-11-09 15:07:42.695 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.client.RestTemplate : GET request for "https://graph.facebook.com/v2.3/me?fields=id%2Cabout%2Cage_range%2Caddress%2Cbio%2Cbirthday%2Ccontext%2Ccover%2Ccurrency%2Cdevices%2Ceducation%2Cemail%2Cfavorite_athletes%2Cfavorite_teams%2Cfirst_name%2Cgender%2Chometown%2Cinspirational_people%2Cinstalled%2Cinstall_type%2Cis_verified%2Clanguages%2Clast_name%2Clink%2Clocale%2Clocation%2Cmeeting_for%2Cmiddle_name%2Cname%2Cname_format%2Cpolitical%2Cquotes%2Cpayment_pricepoints%2Crelationship_status%2Creligion%2Csecurity_settings%2Csignificant_other%2Csports%2Ctest_group%2Ctimezone%2Cthird_party_id%2Cupdated_time%2Cverified%2Cvideo_upload_limits%2Cviewer_can_send_gift%2Cwebsite%2Cwork" resulted in 400 (Bad Request); invoking error handler
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : Error from Facebook: {"error":{"message":"(#3) Application does not have the capability to make this API call.","type":"OAuthException","code":3,"fbtrace_id":"HB0Fe9k\/zM1"}}
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : Facebook error:
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : CODE : 3
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : TYPE : OAuthException
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : SUBCODE : null
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : MESSAGE : (#3) Application does not have the capability to make this API call.
2015-11-09 15:07:42.696 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : USER TITLE : null
2015-11-09 15:07:42.719 DEBUG 14198 --- [nio-8181-exec-4] o.s.s.f.api.impl.FacebookErrorHandler : USER MESSAGE: null
2015-11-09 15:07:42.719 WARN 14198 --- [nio-8181-exec-4] o.s.s.connect.web.ConnectController : Exception while handling OAuth2 callback ((#3) Application does not have the capability to make this API call.). Redirecting to facebook connection status page.
2015-11-09 15:07:42.719 DEBUG 14198 --- [nio-8181-exec-4] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.RedirectView: unnamed; URL [/connect/facebook]] in DispatcherServlet with name 'dispatcherServlet'
答案 0 :(得分:0)
扩展两个春季社交类ConnectResource& ConnectSupport和 覆盖callback_url或aplicationUrl你的问题 解决