Announcement Announcement Module
Collapse
No announcement yet.
linkedInTemplate.profileOperations().getUserProfil eFull() throws exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • linkedInTemplate.profileOperations().getUserProfil eFull() throws exception

    I am using spring-socialilinked for api calls to linkedin and it throws exception when i try to get users's full profile.

    Code:
    linkedInTemplate.profileOperations().getUserProfileFull()
    Code:
    java.net.UnknownHostException: api.linkedin.com/v1/people/~
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
    I guess it is because of ':' for field selectors. Please suggest something

  • #2
    I just used that same method and it worked fine for me. I wouldn't think the ':' would have anything to do with this...that is, after all, how you do field selection with the LinkedIn API and it comes well after the hostname, so it shouldn't be interpreted as a port selector.

    I am wondering which version of Spring Social LinkedIn you're using and whether or not you have Apache HTTP Components in your classpath or not? (In other words, is Spring Social using HTTP Components or relying on the JDK for network connections?) Without knowing more, I'd guess that you do not have HTTP Components and that the JDK's network stuff doesn't like that ':'. If so, try adding Apache HTTP Components to your project and see if that clears things up.

    Comment


    • #3
      Actually, I just tried it both with and without HTTP Components and it still worked as expected...so that may not be your problem at all.

      I'm puzzled...is there any more you can share? Perhaps a more complete stack trace? Anything that might shed light on the problem?

      Comment


      • #4
        This is full stacktrace :-

        Code:
        org.springframework.web.client.ResourceAccessException: I/O error: api.linkedin.com/v1/people/~; nested exception is java.net.UnknownHostException: api.linkedin.com/v1/people/~
        	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
        	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
        	at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
        	at org.springframework.social.linkedin.api.impl.ProfileTemplate.getUserProfileFull(ProfileTemplate.java:83)
        	at com.example.LinkedInCollect.getUpdates(LinkedInCollect.java:102)
        	at com.example.LinkedInCollect.main(LinkedInCollect.java:111)
        Caused by: java.net.UnknownHostException: api.linkedin.com/v1/people/~
        	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
        	at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
        	at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
        	at java.net.InetAddress.getAllByName(InetAddress.java:1084)
        	at java.net.InetAddress.getAllByName(InetAddress.java:1020)
        	at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:242)
        	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:130)
        	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
        	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
        	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
        	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
        	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:700)
        	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:625)
        	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:603)
        	at org.springframework.social.support.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:81)
        	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:56)
        	at org.springframework.social.oauth1.Spring30OAuth1RequestFactory$OAuth1SigningRequest.execute(Spring30OAuth1RequestFactory.java:72)
        	at org.springframework.social.linkedin.api.impl.JsonFormatHeaderRequestFactory$JsonFormatWrappedRequest.execute(JsonFormatHeaderRequestFactory.java:59)
        	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:438)
        	... 5 more
        This is simple code :-

        Code:
        LinkedInTemplate linkedInTemplate = new LinkedInTemplate(consumerKey, consumerKeySecret, accessToken, accessTokenSecret);
        System.out.println("profile : " + linkedInTemplate.profileOperations().getUserProfileFull());
        i have commons-httpclient-3.1.jar and spring-social-linkedin-1.0.0.RC1.jar on classpath.

        Comment


        • #5
          Well, I still don't know for sure, but one thing that stuck out to me is that you're using commons-httpclient-3.1.jar and what I'm recommending is Apache HTTP Components HttpClient (which is what Commons HttpClient became with version 4.x). Specifically, I'm using the following Maven dependency:

          Code:
          <dependency>
          	<groupId>org.apache.httpcomponents</groupId>
          	<artifactId>httpclient</artifactId>
          	<version>4.2.1</version>
          </dependency>
          Even so, I tried switching out that dependency for commons-httpclient-3.1.jar and it still worked. And, looking at your stack trace, it seems to indicate that you're also using HTTP Components HttpClient and not Commons HttpClient as you've indicated....so I'm still unsure what's going on.

          FWIW, here's the code I'm using to try this (substitute your own values for the constants):

          Code:
          package org.springframework.social.linkedin;
          
          import org.springframework.social.linkedin.api.LinkedInProfileFull;
          import org.springframework.social.linkedin.api.impl.LinkedInTemplate;
          
          public class Main {
          
          	private static final String CONSUMER_KEY = "...";
          	private static final String CONSUMER_SECRET = "...";
          	private static final String ACCESS_TOKEN = "...";
          	private static final String ACCESS_TOKEN_SECRET = "...";
          	
          	public static void main(String[] args) {
          		
          		LinkedInTemplate linkedin = new LinkedInTemplate(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
          		LinkedInProfileFull userProfile = linkedin.profileOperations().getUserProfileFull();
          		
          		System.out.println(userProfile.getFirstName() + " " + userProfile.getLastName());
          		
          	}
          	
          }
          And this works perfectly. I can only speculate at this point, but given that you say you're using Commons HTTP Client 3.1 and the stack trace indicates that you're using HTTP Components HttpClient, is it possible that you have some conflicts in your classpath? Can you post a simple (stripped down to nothing but the broken code) example to GitHub that I could checkout and try on my end? I clearly can't recreate it, so it'd be helpful if I could actually work with the broken code.

          Comment

          Working...
          X