无法使用Spring Social连接到Twitter:error = provider

时间:2013-06-17 10:00:23

标签: java spring twitter oauth spring-social

我正在尝试使用Spring社交来获取Twitter连接。 为此,我按照文档编写了这个文件:

@Configuration
public class SocialConfig {

    @Value("${facebook.clientId}")
    private String facebookClientId;
    @Value("${facebook.clientSecret}")
    private String facebookClientSecret;

    @Value("${twitter.consumerKey}")
    private String twitterConsumerKey;
    @Value("${twitter.consumerSecret}")
    private String twitterConsumerSecret;

    @Inject
    private DataSource dataSource;

    /**
     * When a new provider is added to the app, register its
     * {@link ConnectionFactory} here.
     * 
     * @see FacebookConnectionFactory
     */
    @Bean
    public ConnectionFactoryLocator connectionFactoryLocator() {
        ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
        registry.addConnectionFactory(new FacebookConnectionFactory(
                facebookClientId, facebookClientSecret));
        registry.addConnectionFactory(new TwitterConnectionFactory(
                twitterConsumerKey, twitterConsumerSecret));
        return registry;
    }

    /**
     * Singleton data access object providing access to connections across all
     * users.
     */
    @Bean
    public UsersConnectionRepository usersConnectionRepository() {
        JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(
                dataSource, connectionFactoryLocator(), Encryptors.noOpText());
        repository.setConnectionSignUp(new SimpleConnectionSignUp());
        return repository;
    }

    /**
     * Request-scoped data access object providing access to the current user's
     * connections.
     */
    @Bean
    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    public ConnectionRepository connectionRepository() {
        User user = SecurityContext.getCurrentUser();
        return usersConnectionRepository().createConnectionRepository(
                user.getId());
    }

    @Bean
    public ConnectController connectController(){
        return new ConnectController(connectionFactoryLocator(), connectionRepository());
    }

    /**
     * A proxy to a request-scoped object representing the current user's
     * primary Facebook account.
     * 
     * @throws NotConnectedException
     *             if the user is not connected to facebook.
     */
    @Bean
    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    public Facebook facebook() {
        return connectionRepository().getPrimaryConnection(Facebook.class)
                .getApi();
    }

    @Bean
    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    public Twitter twitter() {
        Connection<Twitter> connection = connectionRepository()
                .findPrimaryConnection(Twitter.class);
        Twitter twitter = connection != null ? connection.getApi()
                : new TwitterTemplate();
        return twitter;
    }
}

此代码在facebook上正常运行,但是在twitter中我遇到了提供商=错误。所有键都是正确的(Twitter键与Twitter4j一起使用)。 当我尝试连接时,应用程序将我发送到twitter,然后通过地址中的“error = provider”将其发回给我。

0 个答案:

没有答案