alfdev / linkedin-j

Automatically exported from code.google.com/p/linkedin-j
0 stars 0 forks source link

Get out-of-network profile data #29

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Thanks for the toolkit - most useful!

I needed to be able to search for people using name and company, and then
get the person's public URL.  I think to do that I need to get a search
result and then ask for the Person with ProfileField.PUBLIC_PROFILE_URL. 
Some of those results will be outside of my network, and to get
out-of-network profile data by ID it appears that the headers from a
previous search need to be provided.  

If there is a better way to get that information let me know, but what I
did was add a new getProfileById method to LinkedInApiClient.java and
BaseLinkedInApiClient.java.

LinkedInApiClient.java:

    /**
     * Gets the profile by id, request and fields.
     * For details see <a
href="http://developer.linkedin.com/docs/DOC-1002">http://developer.linkedin.com
/docs/DOC-1002</a>
     * 
     * @param id the profile id 
     * @param headers the request headers
     * @param profileFields the profile fields
     * 
     * @return the profile by id
     */
    public Person getProfileById(String id, Headers headers,
Set<ProfileField> profileFields);

BaseLinkedInApiClient.java:

    /**
     * {@inheritDoc}
     */
    @Override
    public Person getProfileById(String id, Headers headers,
Set<ProfileField> profileFields) {
        assertNotNull("id", id);
        assertNotNull("profile fields", profileFields);

        if (headers != null) {
            LinkedInApiUrlBuilder builder =
createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_PROFILE_BY_ID);
            String                apiUrl  = builder.withField("id",
id).withFieldEnum("profileType",

ProfileType.STANDARD).withFieldEnumSet("profileFields",
                                                    profileFields).buildUrl();

            return readResponse(Person.class, callApiMethod(apiUrl,
headers.getHttpHeaderList()));
        } else {
            return getProfileById(id, profileFields);
        }
    }

I have *not* run this through any unit tests (ran into throttle limits
during the development...).

Thanks again,
Doug.

Original issue reported on code.google.com by carrglo...@gmail.com on 28 May 2010 at 1:27

GoogleCodeExporter commented 9 years ago
Hi Doug
Sorry for the late reply.
There is another method, getProfileByApiRequest() that will be useful to get 
out of network profiles. Here's some example code.

People people = client.searchPeople(searchParameters);
for (Person person : people.getPersonList()) {
    person = client.getProfileByApiRequest(person.getApiStandardProfileRequest());
}

Hope this helps.

Regards
Nabeel Mukhtar

Original comment by nabeelmukhtar on 11 Jun 2010 at 7:16

GoogleCodeExporter commented 9 years ago
Hi Nabeel,

That looks like it would be an alternative, but would still need a new method 
that takes a Set<ProfileField> so more than the default set of fields would be 
returned for the Person?

I also need to be able to requery the data in the future, so would need to 
either recreate the ApiStandardProfileRequest object or recreate the list of 
headers. Seemed easier to just recreate the header list, but what seems easy 
now may not be the best long term decision...

Thanks,
Doug. 

Original comment by carrglo...@gmail.com on 11 Jun 2010 at 4:18

GoogleCodeExporter commented 9 years ago
I run the code by getProfileByApiRequest() but it shows the error in the 
console:
Exception in thread "main" java.lang.IllegalArgumentException: api request 
cannot be null.
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.assertNotNull(BaseLinkedInApiClient.java:3981)
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.getProfileByApiRequest(BaseLinkedInApiClient.java:1130)
    at com.bfs.ibp.spotlight.linkedin.RequiredLinkedinInfo.main(RequiredLinkedinInfo.java:77
)
pls help me in this matter.

Original comment by diptargh...@gmail.com on 21 Dec 2012 at 4:47