Announcement Announcement Module
Collapse
No announcement yet.
Multiple Connections to Multiple Social Networking Accounts? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Connections to Multiple Social Networking Accounts?

    Hi All,

    Does anyone know where the documentation for Multiple connections to Multiple Twitter/LinkedIN Accounts is stored? Or any example Sample Spring Social Apps based on it?.

    Or just basically any good pointer in that direction. Thanks to Habuma, I have got my Spring Social MVC up and running along with a DB connection. Now , my next move is to support mutiple Twitter/LinkedIn accounts. Could you please help me with this?

    Also, I wanted to ask if Spring Social supports tweets/updates in multiple languages? Basically, there would be twitter/linkedin accounts from Eastern European countries which have many special symbols.

    Thanks a lot in advance ,

    Neil

  • #2
    Something like this?
    PHP Code:
    public class MultipleConnectionFactoryRegistry implements ConnectionFactoryLocator {

        /*
         * Structure will be 
         * siteKey
         *         provider
         *             connectionFactory
         */
        private final Map<String,Map<String, ConnectionFactory<?>>> connectionFactories = new HashMap<String, Map<String,ConnectionFactory<?>>>();

        private final Map<Class<?>, String> apiTypeIndex = new HashMap<Class<?>, String>();
        
        public void addConnectionFactory(ConnectionFactory<?> connectionFactory, String key){
            
            if (connectionFactories.get(key) != null && connectionFactories.get(key).containsKey(connectionFactory.getProviderId())) {
                throw new IllegalArgumentException("A ConnectionFactory for provider '" + connectionFactory.getProviderId() + "' has already been registered");
            }

            Class<?> apiType = GenericTypeResolver.resolveTypeArgument(connectionFactory.getClass(), ConnectionFactory.class);

            Map<String,ConnectionFactory<?>> fact = connectionFactories.get(key);
            
            if(fact == null){
                fact = new HashMap<String,ConnectionFactory<?>>();
                connectionFactories.put(key, fact);
            }
            
            fact.put(connectionFactory.getProviderId(), connectionFactory);
            
            apiTypeIndex.put(apiType, connectionFactory.getProviderId());
        }
        
        public void addConnectionFactory(ConnectionFactory<?> connectionFactory) {
            throw new RuntimeException("Should use addConnectionFactory(ConnectionFactory<?> connectionFactory, String key)");
        }

        public void setConnectionFactories(List<ConnectionFactory<?>> connectionFactories) {
            for (ConnectionFactory<?> connectionFactory : connectionFactories) {
                addConnectionFactory(connectionFactory);
            }
        }
        
        @Override
        public ConnectionFactory<?> getConnectionFactory(String providerId) {
            ConnectionFactory<?> connectionFactory = connectionFactories.get(SocialRequestUtils.getKey()).get(providerId);
            if (connectionFactory == null) {
                throw new IllegalArgumentException("No connection factory for service provider '" + providerId + "' is registered");
            }
            return connectionFactory;
        }

        @Override
        @SuppressWarnings("unchecked")
        public <A> ConnectionFactory<A> getConnectionFactory(Class<A> apiType) {
            String providerId = apiTypeIndex.get(apiType);
            if (providerId == null) {
                throw new IllegalArgumentException("No connection factory for API [" + apiType.getName() + "] is registered");
            }
            return (ConnectionFactory<A>) getConnectionFactory(providerId);
        }

        @Override
        public Set<String> registeredProviderIds() {
            return connectionFactories.get(SocialRequestUtils.getKey()).keySet();
        }

    }

    Comment


    • #3
      Hi,

      Thanks for that. I am having some issues in executing this in Java though. I am currently using SocialConfig/ExplicitSocialConfig for configuring my connections.For this file where do I make entries in? I mean to say which files do I modify?. Also, I cant find SocialRequestUtils in any of my packages.

      Could you please help me with this

      Comment


      • #4
        This isjust from a project I have. SocialRequestUtils uses a ThreadLocal pattern to store and retrieve the current provider id. You might use other methods to achieve this. This is what I used.

        PHP Code:
        public class SocialRequestUtils {
            
            private static final 
        ThreadLocal<StringuserThread = new ThreadLocal<String>();
            
            private static final 
        Log log LogFactory.getLog(SocialRequestUtils.class);
            
            public static 
        void setKey(String key){
                
        userThread.set(key);
            }
            
            public static 
        String getKey(){
                if(
        userThread.get() == null){
                    
        log.error("Missing threadLocale variable ");
                }
                
                return 
        userThread.get();
            }

        Comment

        Working...
        X