This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
/
api.xml
92 lines (71 loc) · 4 KB
/
api.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="apis" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>LinkedIn API Binding</title>
<para>
Spring Social LinkedIn offers integration with LinkedIn's REST API with the <interfacename>LinkedIn</interfacename> interface and its implementation, <classname>LinkedInTemplate</classname>.
</para>
<para>
To create an instance of <classname>LinkedInTemplate</classname>, you may pass in your application's OAuth 1 credentials, along with an access token/secret pair to the constructor:
</para>
<programlisting language="java"><![CDATA[
String consumerKey = "..."; // The application's consumer key
String consumerSecret = "..."; // The application's consumer secret
String accessToken = "..."; // The access token granted after OAuth authorization
String accessTokenSecret = "..."; // The access token secret granted after OAuth authorization
LinkedIn linkedin = new LinkedInTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);]]>
</programlisting>
<para>
If you are using Spring Social's <ulink url="http://static.springsource.org/spring-social/docs/1.0.x/reference/html/serviceprovider.html">service provider framework</ulink>, you can get an instance of <interfacename>LinkedIn</interfacename> from a <interfacename>Connection</interfacename>.
For example, the following snippet calls <methodname>getApi()</methodname> on a connection to retrieve a <interfacename>LinkedIn</interfacename>:
</para>
<programlisting language="java"><![CDATA[
Connection<LinkedIn> connection = connectionRepository.findPrimaryConnection(LinkedIn.class);
if (connection != null) {
LinkedIn linkedin = connection.getApi();
// ... use LinkedIn API binding
}]]>
</programlisting>
<para>
Here, <interfacename>ConnectionRepository</interfacename> is being asked for the primary connection that the current user has with LinkedIn.
If a connection to LinkedIn is found, it retrieves a <interfacename>LinkedIn</interfacename> instance that is configured with the connection details received when the connection was first established.
</para>
<para>
Once you have a <interfacename>LinkedIn</interfacename> you can use it to interact with LinkedIn on behalf of the user who the access token was granted for.
</para>
<section id="linkedin-getProfile">
<title>Retrieving a user's LinkedIn profile data</title>
<para>
To retrieve the authenticated user's profile data, call the <methodname>getUserProfile()</methodname> method:
</para>
<programlisting language="java"><![CDATA[
LinkedInProfile profile = linkedin.getUserProfile();]]>
</programlisting>
<para>
The data returned in the <classname>LinkedInProfile</classname> includes the user's LinkedIn ID, first and last names, their "headline", the industry they're in, and URLs for the public and standard profile pages.
</para>
<para>
If it's only the user's LinkedIn ID you need, then you can get that by calling the <methodname>getProfileId()</methodname> method:
</para>
<programlisting language="java"><![CDATA[
String profileId = linkedin.getProfileId();]]>
</programlisting>
<para>
Or if you only need a URL for the user's public profile page, call <methodname>getProfileUrl()</methodname>:
</para>
<programlisting language="java"><![CDATA[
String profileUrl = linkedin.getProfileUrl();]]>
</programlisting>
</section>
<section id="linkedin-connections">
<title>Getting a user's LinkedIn connections</title>
<para>
To retrieve a list of LinkedIn users to whom the user is connected, call the <methodname>getConnections()</methodname> method:
</para>
<programlisting><![CDATA[
List<LinkedInProfile> connections = linkedin.getConnections();]]>
</programlisting>
<para>
This will return a list of <classname>LinkedInProfile</classname> objects for the user's 1st-degree network (those LinkedIn users to whom the user is directly linked--not their extended network).
</para>
</section>
</chapter>