【发布时间】:2023-03-07 11:25:01
【问题描述】:
我开发了一个简单的 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>
由启动 OAuth 授权代码流的 ConnectController 处理...
在 OAuth 成功(授予权限)并完成连接后,我收到以下错误:
(#3) 应用程序无法进行此 api 调用。
这里是控制器的主要部分,用于处理来自 Facebook 应用程序的重定向:
@Controller
@Scope(value="session") 公共类 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");
}
}
查看堆栈跟踪错误,似乎我在控制器的这一行出现错误:
用户用户 = facebook.userOperations().getUserProfile();
但这很奇怪,因为默认情况下我应该有权获取基本的用户配置文件数据。
注意:与 Facebook 中使用 Graph API 版本 2.3 的旧应用程序相同的代码可以完美运行,但我需要一个用于不同目的的新应用程序,并且不能强制 Facebook 中的新应用程序使用该版本。 ..
这是我得到的堆栈错误....
12:01:16.953 [http-nio-9080-exec-5] 错误 o.a.c.c.C.[.[.[.[dispatcherServlet]] - Servlet.service() 用于 servlet [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] 在 org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:59) ~[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:253) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:214) ~[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:209) ~[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:53) ~[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:49) ~[spring-social-facebook-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 it.cerict.recommender.extractor.controllers.FacebookExtractor.FacebookDataUserExtraction(FacebookExtractor.java:89) ~[classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native 方法)~[na:1.8.0_60] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60] 在 java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60] 在 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 it.cerict.recommender.config.CORSFilter.doFilter(CORSFilter.java:22) 〜[类/:na]在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60] 在 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.26.jar:8.0.26] 在 java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
【问题讨论】:
标签: spring facebook-graph-api spring-social-facebook