I need to get the connections of a user whose id is yZTcaxINNv. I use linkedin-j and the code looks something like this
import com.google.code.linkedinapi.client.LinkedInApiClient;
import com.google.code.linkedinapi.client.LinkedInApiClientFactory;
import com.google.code.linkedinapi.schema.Connections;
import com.google.code.linkedinapi.schema.Person;
public class Linkedin_Data_Extract {
public static void main(String[] args) {
final String consumerKeyValue = "My key";
final String consumerSecretValue ="My Secret";
final String accessTokenValue = "Access Token";
final String tokenSecretValue = "Secret";
final String id = "yZTcaxINNv";
final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(consumerKeyValue, consumerSecretValue);
final LinkedInApiClient client = factory.createLinkedInApiClient(accessTokenValue, tokenSecretValue);
Connections cc=client.getConnectionsById(id);
for(Person p :cc.getPersonList()) {
System.out.println(p.getLastName());
System.out.println(p.getId());
System.out.println("Industry "+p.getIndustry());
System.out.println("currentStatus "+p.getCurrentStatus());
System.out.println("link "+p.getPublicProfileUrl());
System.out.println("position "+p.getEducations());
System.out.println();
}
}
}
But i get an error like this
Exception in thread "main" com.google.code.linkedinapi.client.LinkedInApiClientException: Access to connections denied
at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.createLinkedInApiClientException(BaseLinkedInApiClient.java:3906)
at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(BaseLinkedInApiClient.java:3781)
at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(BaseLinkedInApiClient.java:3725)
at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.getConnectionsById(BaseLinkedInApiClient.java:235)
at Linkedin_Data_Extract.main(Linkedin_Data_Extract.java:27)
Why am i getting permission issues
Third-party APIs that access other users information through OAuth need to be explicitly allowed permission by the user himself.
Normally, this happens through a popup window where the user is asked to allow/reject your app to operate on his data. I'm guessing this is where your issue comes from.
I don't know how linkedin-j does this, but in case you are up for alternatives, you could give Spring Social a try, which has a module addressed specifically for Linkedin. See the Quickstart sample in the page I gave you if you're curious