我开发了一个简单的Web应用程序,通过Spring Boot(v1.2.6.RELEASE)和Spring Social Facebook(v2.0.2.RELEASE)访问Facebook数据,类似于给出here的示例
我在Facebook上创建了一个使用Graph API版本2.5的新应用程序。
根据这个例子,我修改了facebookConnect.html,将这个不同的范围放到方法POST请求中:
<html>
<head>
<title>Facebook Extractor</title>
</head>
<body>
<h3>Connect to Facebook</h3>
<form action="/recommender/connect/facebook" method="POST">
<input type="hidden" name="scope" value="public_profile, user_friends, email, user_likes" />
<div class="formInfo">
<p>You aren't connected to Facebook yet. Click the button to connect this application with your Facebook account.</p>
</div>
<p><button type="submit">Connect to Facebook</button></p>
</form>
</body>
由ConnectController处理,启动OAuth授权代码流...
OAuth成功(授予权限)并完成连接后,我收到以下错误:
(#3)应用程序无法进行此api调用。
这里是处理来自Facebook App的重定向的控制器的主要部分:
@Controller
@Scope(值=&#34;会话&#34) 公共类FacebookExtractor {
private Logger logger = Logger.getLogger(FacebookExtractor.class);
private Facebook facebook;
@Autowired
GraphDatabase graphDatabase;
@Autowired
PersonRepository personRepository;
@Autowired
UserProfileRepository userProfileRepository;
@Autowired
AttributeDefinitionRepository attributeDefinitionRepository;
@Autowired
AttributeRepository attributeRepository;
@Autowired
ConceptRepository conceptRepository;
@Autowired
RecommenderGovConsumerRepository recGovRepository;
@Autowired
GovConsumerInfluencedByGovConsumerRelationshipRepository influenceRepository;
@Autowired
ExtractorListener listener;
private String userBind;
@Inject
public FacebookExtractor(Facebook facebook) {
this.facebook = facebook;
}
@RequestMapping(method = RequestMethod.GET, value = "/facebookExtractor")
public ModelAndView FacebookDataUserExtraction() {
if (!facebook.isAuthorized()) {
return new ModelAndView("redirect:/recommender/connect/facebook");
}
String account=userBind;
Long netId = null;
Transaction tx = graphDatabase.beginTx();
try {
User user = facebook.userOperations().getUserProfile();
Person p = savePerson(user);
UserProfile up = saveUserProfile(user);
up.setUser(p);
userProfileRepository.save(up);
p.setProfile(up);
saveSocialInteractions(up);
saveSocialPreferences(up);
personRepository.save(p);
netId=p.getId();
tx.success();
} finally {
tx.close();
}
if (account != null) {
/*
* Binding di Facebook riuscito.
*/
listener.onProfileDataCompleted(netId, SNAccountType.Facebook);
listener.onInteractionsCompleted(netId, InteractionType.Friendship, SNAccountType.Facebook);
return new ModelAndView("redirect:http://localhost:8080/portal",
"accountF", account);
} else {
//vista opportuna per estrazione avvenuta senza bind
return new ModelAndView("facebookNoBindExtraction");
}
}
观察堆栈跟踪错误,似乎我在控制器中的这一行收到错误:
User user = facebook.userOperations()。getUserProfile();
但很奇怪,因为默认情况下我应该有权获取基本的用户个人资料数据。
注意:与使用Graph API版本2.3的旧版应用程序相同的代码可以很好地工作,但我需要一个新的用于不同目的的代码,并且不能强迫Facebook中的新应用程序使用该代码版本...
这里是我得到的堆栈错误....
12:01:16.953 [http-nio-9080-exec-5]错误 o.a.c.c.C。[。[。[。[dispatcherServlet] - 用于servlet的Servlet.service() 路径[]的上下文中的[dispatcherServlet]抛出异常[Request 处理失败;嵌套异常是 org.springframework.social.UncategorizedApiException:(#3)应用程序 无法根据原因进行此API调用 org.springframework.social.UncategorizedApiException:(#3)应用程序 没有能力进行此API调用。在 org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleFacebookError(FacebookErrorHandler.java:91) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:59) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:253) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:214) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:209) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:53) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:49) 〜[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] at it.cerict.recommender.extractor.controllers.FacebookExtractor.FacebookDataUserExtraction(FacebookExtractor.java:89) 〜[classes /:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native 方法)〜[na:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 〜[na:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 〜[na:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) 〜[na:1.8.0_60] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) 〜[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 〜[tomcat-embed-websocket-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at it.cerict.recommender.config.CORSFilter.doFilter(CORSFilter.java:22) 〜[classes /:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 〜[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) 〜[tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1526) [tomcat-embed-core-8.0.26.jar:8.0.26] at org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1482) [tomcat-embed-core-8.0.26.jar:8.0.26] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60] at java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60] at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.26.jar:8.0.26] at java.lang.Thread.run(Thread.java:745)[na:1.8.0_60]
答案 0 :(得分:3)
问题在于
中的PROFILE_FILEDSpublic User getUserProfile(String facebookId) {
return graphApi.fetchObject(facebookId, User.class, PROFILE_FIELDS);
}
数组PROFILE_FIELDS包含许多字段,因为我正确地说明了春季社交文档,Facebook只返回了您有权查看的字段。 但现在发生了变化:
$curl "https://graph.facebook.com/v2.5/me?access_token=[access_tokens]&fields=[all_the_fields_from_PROFILE_FIELDS]
{"error":{"message":"(#3) Application does not have the capability to make this API call.","type":"OAuthException","code":3,"fbtrace_id":"Antivssjj1d"}}
$ curl "https://graph.facebook.com/v2.3/me?access_token=[access_token]&fields=id,about"
{"id":"1135898619755433"}
与此同时,我发现了溶解。代替
User profile = facebook.userOperations().getUserProfile()
我们可以使用
User profile = facebook.fetchObject("me", User.class, "id", "name", "link", "email");
//Note: facebook = org.springframework.social.facebook.api.Facebook
//Note: User.class = org.springframework.social.facebook.api.User.class
答案 1 :(得分:0)
或者等待spring-social-facebook的更新,存储库中有一个待处理的拉取请求:https://github.com/spring-projects/spring-social-facebook/pull/171
更新:使用2.0.3.RELEASE
版本为我修复。
答案 2 :(得分:0)
即使添加了我的应用所需的publish_actions
范围,我仍然会收到此错误。我的问题是我需要Facebook来审核我的应用程序。如果您的应用程序是在2014年4月30日之后创建的,并且满足以下一个或多个条件,则会出现这种情况:
有关审核流程的更多信息,请查看Facebook Login Review FAQs。