我正在使用Spring Social Facebook插件;我有一个非常简单的场景:我想在我的网页上显示我的用户帐户Feed;到目前为止,我已经构建了一个非常简单的JUnit测试,以便列出我的FB墙帖,但我面临一些Spring社交集成的问题 我正在使用spring 4.0.5和spring social 1.1.0
从我在文档中看到的,我不需要使用spring社交连接框架(也许我将来会使用ConnectionRepository,以便不会在每个请求上总是进行FB和/或twitter连接,但现在我不需要处理几个用户)
因此,在我在FB上创建测试APP并获得appClientID和appClientSecret之后,我编写了这个简单的XML配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:facebook="http://www.springframework.org/schema/social/facebook"
xmlns:twitter="http://www.springframework.org/schema/social/twitter"
xmlns:social="http://www.springframework.org/schema/social"
xmlns:linkedin="http://www.springframework.org/schema/social/linkedin"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd
http://www.springframework.org/schema/social/linkedin http://www.springframework.org/schema/social/spring-social-linkedin.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/social/twitter http://www.springframework.org/schema/social/spring-social-twitter.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:configuration.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
<context:component-scan base-package="it.spring" />
<bean id="connectionFactoryLocator"
class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
<property name="connectionFactories">
<list>
<bean
class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
<constructor-arg value="${facebook.appKey}" />
<constructor-arg value="${facebook.appSecret}" />
</bean>
<bean
class="org.springframework.social.twitter.connect.TwitterConnectionFactory">
<constructor-arg value="${twitter.appKey}" />
<constructor-arg value="${twitter.appSecret}" />
</bean>
</list>
</property>
</bean>
</beans>
我写了这个简单的java类(我在代理后面,但我可以到达FB ......我的网络管理员授予我到FB):
public class SocialNetworkSvcImpl implements SocialNetworkingSvc
{
private static final Log logger = LogFactory.getLog(SocialNetworkSvcImpl.class.getName());
@Autowired
private Environment env;
@Value("${facebook.appId}")
private String facebookAppId;
@Value("${facebook.appSecret}")
private String facebookAppSecret;
@Value("${facebook.clientToken}")
private String facebookClientToken;
@Value("${facebook.appNamespace}")
private String facebookAppNamespace;
private ClientHttpRequestFactory requestFactory;
@Autowired
private ConnectionFactoryRegistry cfr;
@Override
public PagedList<Post> getPosts() throws Exception
{
try
{
FacebookConnectionFactory fcc = (FacebookConnectionFactory)cfr.getConnectionFactory("facebook");
Facebook facebook = fcc.createConnection(fcc.getOAuthOperations().authenticateClient()).getApi();
if( proxyEnabled )
{
if( requestFactory != null )
{
((FacebookTemplate)facebook).setRequestFactory(requestFactory);
}
else
{
throw new IllegalArgumentException("Impossibile settare la requestFactory; proxy abilitato ma requestFactory null");
}
}
PagedList<Post> result = facebook.feedOperations().getHomeFeed();
result.addAll(facebook.feedOperations().getFeed());
return result;
}
catch (Exception e)
{
String messagge = "Errore nel recupero feed: "+e.getMessage();
logger.fatal(messagge, e);
throw e;
}
}
@PostConstruct
public void initialize()
{
if( proxyEnabled )
{
if( !StringUtils.hasText(proxyHost) )
{
throw new IllegalArgumentException("Impossibile proseguire; valore proxyHost non ammesso: "+proxyHost);
}
if( proxyPort <= 0 )
{
throw new IllegalArgumentException("Impossibile proseguire; valore proxyPort non ammesso: "+proxyPort);
}
if( !StringUtils.hasText(basicHeaderValue) )
{
throw new IllegalArgumentException("Impossibile proseguire; valore basicHeaderValue non ammesso: "+basicHeaderValue);
}
String userName = null;
String password = null;
if( !StringUtils.hasText(proxyAuthUsername) )
{
if( logger.isInfoEnabled() )
{
logger.info("Nessun valore per proxyAuthUsername; controllo se siamo nel profilo sviluppo e se è presente come paramteri della JVM");
}
boolean svil = false;
String[] profili = env.getActiveProfiles();
for (int i = 0; i < profili.length; i++)
{
if( profili[i].equalsIgnoreCase("svil") )
{
svil = true;
break;
}
}
if( svil )
{
if(System.getProperty("usernameProxy") != null)
{
userName = System.getProperty("usernameProxy");
}
}
}
else
{
if( logger.isInfoEnabled() )
{
logger.info("Valorizzo la username del proxy dal file di properties");
}
userName = proxyAuthUsername;
}
if( !StringUtils.hasText(proxyAuthPassword) )
{
if( logger.isInfoEnabled() )
{
logger.info("Nessun valore per proxyAuthPassword; controllo se siamo nel profilo sviluppo e se è presente come paramteri della JVM");
}
boolean svil = false;
String[] profili = env.getActiveProfiles();
for (int i = 0; i < profili.length; i++)
{
if( profili[i].equalsIgnoreCase("svil") )
{
svil = true;
break;
}
}
if( svil )
{
if(System.getProperty("passwordProxy") != null)
{
password = System.getProperty("passwordProxy");
}
}
}
else
{
if( logger.isInfoEnabled() )
{
logger.info("Valorizzo la password del proxy dal file di properties");
}
password = proxyAuthPassword;
}
if( (StringUtils.hasText(userName) && !StringUtils.hasText(password)) || (!StringUtils.hasText(userName) && StringUtils.hasText(password)) )
{
throw new IllegalArgumentException("Impossibile proseguire; settata solo "+(StringUtils.hasText(userName)?" la username ":" la password ")+" per accesso al proxy");
}
try
{
requestFactory = new HttpComponentsClientHttpRequestFactory();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
CredentialsProvider credsProvider = null;
if( (StringUtils.hasText(userName) && StringUtils.hasText(password)) )
{
credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(userName, password));
}
HttpClientBuilder builder = HttpClients.custom();
if( credsProvider != null )
{
builder.setDefaultCredentialsProvider(credsProvider);
}
builder.setProxy(proxy);
CloseableHttpClient httpClient = builder.build();
((HttpComponentsClientHttpRequestFactory)requestFactory).setHttpClient(httpClient);
}
catch (Exception e)
{
String message = "Errore nell'inizializzazione del servizio di connessione a social network: "+e.getMessage();
logger.fatal(message, e);
throw new IllegalStateException(message);
}
}
else
{
if( logger.isInfoEnabled() )
{
logger.info("Proxy non abilitato; ci si collega direttamente ai social network");
}
}
}
}
但我有一个错误。这是我的日志:
2014-07-30 09:47:04,717 DEBUG [org.springframework.web.client.RestTemplate] Created POST request for "https://graph.facebook.com/oauth/access_token"
2014-07-30 09:47:04,718 DEBUG [org.springframework.web.client.RestTemplate] Setting request Accept header to [application/x-www-form-urlencoded, multipart/form-data]
2014-07-30 09:47:04,718 DEBUG [org.springframework.web.client.RestTemplate] Writing [{client_id=[${facebook.appKey}], client_secret=[e927afa9c6b3fb7e0e9344e38a5df46b], grant_type=[client_credentials]}] using [org.springframework.social.facebook.connect.FacebookOAuth2Template$1@f653852]
2014-07-30 09:47:04,761 DEBUG [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: best-match
2014-07-30 09:47:04,797 DEBUG [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in the context
2014-07-30 09:47:04,800 DEBUG [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection request: [route: {s}->https://graph.facebook.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
2014-07-30 09:47:04,862 DEBUG [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection leased: [id: 0][route: {s}->https://graph.facebook.com:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
2014-07-30 09:47:04,867 DEBUG [org.apache.http.impl.execchain.MainClientExec] Opening connection {s}->https://graph.facebook.com:443
2014-07-30 09:47:04,890 DEBUG [org.apache.http.impl.conn.HttpClientConnectionOperator] Connecting to graph.facebook.com/173.252.100.27:443
2014-07-30 09:47:04,892 DEBUG [org.apache.http.impl.conn.HttpClientConnectionOperator] Connect to graph.facebook.com/173.252.100.27:443 timed out. Connection will be retried using another IP address
2014-07-30 09:47:04,893 DEBUG [org.apache.http.impl.conn.HttpClientConnectionOperator] Connecting to graph.facebook.com/2a03:2880:2110:cf07:face:b00c:0:1:443
2014-07-30 09:47:04,896 DEBUG [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-0: Shutdown connection
2014-07-30 09:47:04,896 DEBUG [org.apache.http.impl.execchain.MainClientExec] Connection discarded
2014-07-30 09:47:04,897 DEBUG [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-0: Close connection
2014-07-30 09:47:04,897 DEBUG [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 0][route: {s}->https://graph.facebook.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
2014-07-30 09:47:04,901 INFO [org.apache.http.impl.execchain.RetryExec] I/O exception (java.net.SocketException) caught when processing request to {s}->https://graph.facebook.com:443: Network is unreachable
2014-07-30 09:47:04,902 DEBUG [org.apache.http.impl.execchain.RetryExec] Network is unreachable
java.net.SocketException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:52)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:545)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:334)
at org.springframework.social.facebook.connect.FacebookOAuth2Template.postForAccessGrant(FacebookOAuth2Template.java:58)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:194)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:181)
at it.spring.service.impl.SocialNetworkSvcImpl.getPosts(SocialNetworkSvcImpl.java:129)
at it.eng.comi.test.ComiSocialTests.testFeeds(ComiSocialTests.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
2014-07-30 09:47:04,914 INFO [org.apache.http.impl.execchain.RetryExec] Retrying request to {s}->https://graph.facebook.com:443
...
2014-07-30 09:47:11,128 ERROR [it.spring.service.impl.SocialNetworkSvcImpl] Errore nel recupero feed: I/O error on POST request for "https://graph.facebook.com/oauth/access_token":Network is unreachable; nested exception is java.net.SocketException: Network is unreachable
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://graph.facebook.com/oauth/access_token":Network is unreachable; nested exception is java.net.SocketException: Network is unreachable
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:561)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:334)
at org.springframework.social.facebook.connect.FacebookOAuth2Template.postForAccessGrant(FacebookOAuth2Template.java:58)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:194)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:181)
at it.spring.service.impl.SocialNetworkSvcImpl.getPosts(SocialNetworkSvcImpl.java:129)
at it.eng.comi.test.ComiSocialTests.testFeeds(ComiSocialTests.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.net.SocketException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:52)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:545)
... 35 more
2014-07-30 09:47:11,130 ERROR [it.eng.comi.test.ComiSocialTests] I/O error on POST request for "https://graph.facebook.com/oauth/access_token":Network is unreachable; nested exception is java.net.SocketException: Network is unreachable
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://graph.facebook.com/oauth/access_token":Network is unreachable; nested exception is java.net.SocketException: Network is unreachable
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:561)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:334)
at org.springframework.social.facebook.connect.FacebookOAuth2Template.postForAccessGrant(FacebookOAuth2Template.java:58)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:194)
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:181)
at it.spring.service.impl.SocialNetworkSvcImpl.getPosts(SocialNetworkSvcImpl.java:129)
at it.eng.comi.test.ComiSocialTests.testFeeds(ComiSocialTests.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.net.SocketException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:52)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:545)
... 35 more
相反,如果我在FB上生成APP令牌并直接在FacebookTemplate中使用它,那么一切都很好。 我该如何解决这个问题?我错了什么?任何提示真的很感激
谢谢 安吉洛
答案 0 :(得分:0)
我立即看到了一些错误。您遇到的主要问题是网络问题 - 而不是代码问题或Spring Social问题。即使您的网络管理员说您可以看到Facebook,您展示的例外情况也会告诉我。这是你需要解决的问题。
一旦你越过那个,我怀疑这无论如何都会有用。您可以通过authenticateClient()获取访问令牌,该令牌仅授予您客户端令牌。但是,您尝试将其用于特定于用户的请求,例如获取主页Feed。您必须拥有用户令牌才能执行该操作,并且您只能通过用户授权获得用户令牌,即#34; OAuth Dance&#34;。 Spring Social的ConnectController可以为您提供帮助。