Documentation
¶
Overview ¶
Package linkedin provides a thin client for making requests to LinkedIn APIs following the official LinkedIn API documentation.
Index ¶
- Constants
- Variables
- func DecodeURL(text string) (string, error)
- func EncodeURL(text string) string
- type App
- type ContentDataType
- type CoverPhotoV2
- type Created
- type DefaultLocale
- type DistributionPost
- type ElementOrganization
- type ElementPost
- type HTTPClient
- type Header
- type LastModified
- type LifecycleStateInfoPost
- type Link
- type LogoV2
- type Method
- type NameLocalized
- type Organization
- type OrganizationInfo
- type Paging
- type Params
- type Post
- type ReshareContextPost
- type RestLiMethod
- type Result
- type Session
- func (session *Session) AccessToken() string
- func (session *Session) App() *App
- func (session *Session) Context() context.Context
- func (session *Session) Get(uri string) (response *http.Response, data []byte, err error)
- func (session *Session) Introspect(token string) (TokenData, error)
- func (session *Session) SetAccessToken(token string)
- func (session *Session) SetLinkedInVersion(version string)
- func (session *Session) UseAuthorizationHeader()
- func (session *Session) WithContext(ctx context.Context) *Session
- type Token
- type TokenData
Constants ¶
const ( OauthBaseURL = "https://www.linkedin.com/oauth/v2" VersionedBaseURL = "https://api.linkedin.com/rest" )
LinkedIn rest api base urls
See: https://learn.microsoft.com/en-us/linkedin/marketing/versioning?view=li-lms-2024-04
const ( ListPrefix = "List(" ListSuffix = ")" ListItemSep = "," ObjPrefix = "(" ObjSuffix = ")" ObjKeyValSep = ":" ObjKeyValPairSep = "," LeftBracket = "(" RightBracket = ")" )
Rest.Li special characters
Variables ¶
var RestLiMethodToHTTPMethodMap = map[RestLiMethod]Method{ Get: GET, BatchGet: GET, GetAll: GET, Finder: GET, BatchFinder: GET, Update: PUT, BatchUpdate: PUT, Create: POST, BatchCreate: POST, PartialUpdate: POST, BatchPartialUpdate: POST, Action: POST, Delete: DELETE, BatchDelete: DELETE, }
RestLiMethodToHTTPMethodMap - map of LinkedIn Rest.Li methods to HTTP methods
Functions ¶
Types ¶
type App ¶
type App struct {
ClientID string
ClientSecret string
RedirectURI string
// contains filtered or unexported fields
}
App holds the configuration for the LinkedIn application.
ClientID and ClientSecret: https://www.linkedin.com/developers/apps/{appID}/auth
func (*App) RefreshToken ¶ added in v0.1.2
RefreshToken redeems refresh token for new access and refresh tokens.
type ContentDataType ¶
type ContentDataType string
ContentDataType - HTTP content data type
const ( URLEncoded ContentDataType = "application/x-www-form-urlencoded" JSON ContentDataType = "application/json" )
HTTP content data type
type CoverPhotoV2 ¶ added in v0.1.1
type CoverPhotoV2 struct {
Original string `json:"original"`
}
CoverPhotoV2 struct for cover photo
type Created ¶ added in v0.1.1
type Created struct {
Actor string `json:"actor"` // e.g. urn:li:person:a1b2c3
Impersonator string `json:"impersonator"` // e.g. urn:li:servicePrincipal:organization
Time int64 `json:"time"` // e.g. 1612345678901
}
Created struct for created timestamp
type DefaultLocale ¶ added in v0.1.1
type DefaultLocale struct {
Country string `json:"country"` // e.g. US
Language string `json:"language"` // e.g. en
}
DefaultLocale struct for default locale
type DistributionPost ¶ added in v0.1.1
type DistributionPost struct {
FeedDistribution string `json:"feedDistribution"` // e.g. MAIN_FEED
}
DistributionPost struct for LinkedIn post distribution
type ElementOrganization ¶ added in v0.1.1
type ElementOrganization struct {
RoleAssignee string `json:"roleAssignee"` // e.g. urn:li:person:a1b2c3
State string `json:"state"` // e.g. APPROVED
LastModified LastModified `json:"lastModified"`
Role string `json:"role"` // e.g. ADMINISTRATOR
Created Created `json:"created"`
Organization string `json:"organization"` // e.g. urn:li:organization:123456789
}
ElementOrganization struct for LinkedIn organization elements
func (*ElementOrganization) GetOrganizationID ¶ added in v0.1.1
func (e *ElementOrganization) GetOrganizationID() string
GetOrganizationID returns the organization ID from the organization URN
type ElementPost ¶ added in v0.1.1
type ElementPost struct {
CreatedAt int64 `json:"createdAt"`
LifecycleState string `json:"lifecycleState"` // e.g. PUBLISHED
LastModifiedAt int64 `json:"lastModifiedAt"`
Visibility string `json:"visibility"` // e.g. PUBLIC
PublishedAt int64 `json:"publishedAt"`
Author string `json:"author"` // e.g. urn:li:organization:123456
ID string `json:"id"` // e.g. urn:li:ugcPost:123456
Distribution DistributionPost `json:"distribution"`
Commentary string `json:"commentary"` // e.g. Hello, world!
LifecycleStateInfo LifecycleStateInfoPost `json:"lifecycleStateInfo"`
}
ElementPost struct for LinkedIn post elements
type HTTPClient ¶
type HTTPClient interface {
Do(req *http.Request) (resp *http.Response, err error)
Get(url string) (resp *http.Response, err error)
Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
}
HTTPClient is an interface to send http request. It is compatible with type `*http.Client`.
type Header ¶
type Header string
Header - HTTP header data type
const ( ContentType Header = "Content-Type" Connection Header = "Connection" RestLiProtocolVersion Header = "X-RestLi-Protocol-Version" RestLiMethodHeader Header = "X-RestLi-Method" LinkedInVersion Header = "LinkedIn-Version" Authorization Header = "Authorization" UserAgent Header = "user-agent" CreatedEntityID Header = "X-RestLi-Id" )
HTTP headers used in LinkedIn API requests
type LastModified ¶ added in v0.1.1
type LastModified struct {
Actor string `json:"actor"` // e.g. urn:li:person:a1b2c3
Impersonator string `json:"impersonator"` // e.g. urn:li:servicePrincipal:organization
Time int64 `json:"time"` // e.g. 1612345678901
}
LastModified struct for last modified timestamp
type LifecycleStateInfoPost ¶ added in v0.1.1
type LifecycleStateInfoPost struct {
IsEditedByAuthor bool `json:"isEditedByAuthor"`
}
LifecycleStateInfoPost struct for LinkedIn post lifecycle state information
type Link ¶ added in v0.1.1
type Link struct {
Type string `json:"type"` // application/json
Rel string `json:"rel"` // prev, next
Href string `json:"href"`
}
Link struct for pagination
type LogoV2 ¶ added in v0.1.1
type LogoV2 struct {
Original string `json:"original"`
}
LogoV2 struct for logo
type NameLocalized ¶ added in v0.1.1
type NameLocalized struct {
Localized map[string]string `json:"localized"`
PreferredLocale DefaultLocale `json:"preferredLocale"`
}
NameLocalized struct for localized name
type Organization ¶ added in v0.1.1
type Organization struct {
Paging Paging `json:"paging"`
Elements []ElementOrganization `json:"elements"`
}
Organization struct for LinkedIn organizations
type OrganizationInfo ¶ added in v0.1.1
type OrganizationInfo struct {
VanityName string `json:"vanityName"`
LocalizedName string `json:"localizedName"`
Created Created `json:"created"`
VersionTag string `json:"versionTag"`
CoverPhotoV2 CoverPhotoV2 `json:"coverPhotoV2"`
OrganizationType string `json:"organizationType"` // e.g. SELF_OWNED
DefaultLocale DefaultLocale `json:"defaultLocale"`
LocalizedSpecialties []string `json:"localizedSpecialties"`
Name NameLocalized `json:"name"`
PrimaryOrganizationType string `json:"primaryOrganizationType"` // e.g. NONE
LastModified LastModified `json:"lastModified"`
ID int64 `json:"id"` // ID of the organization
LocalizedDescription string `json:"localizedDescription"`
AutoCreated bool `json:"autoCreated"`
LocalizedWebsite string `json:"localizedWebsite"`
LogoV2 LogoV2 `json:"logoV2"`
}
OrganizationInfo struct for LinkedIn organization information
func (*OrganizationInfo) GetOrganizationID ¶ added in v0.1.1
func (oi *OrganizationInfo) GetOrganizationID() int64
GetOrganizationID returns the organization ID from the details of the organization
type Paging ¶ added in v0.1.1
type Paging struct {
Start int `json:"start"`
Count int `json:"count"`
Links []Link `json:"links"`
Total int `json:"total"`
}
Paging struct for pagination
type Post ¶ added in v0.1.1
type Post struct {
Paging Paging `json:"paging"`
Elements []ElementPost `json:"elements"`
}
Post struct for LinkedIn posts
type ReshareContextPost ¶ added in v0.1.1
type ReshareContextPost struct {
}
ReshareContextPost struct for LinkedIn post reshare context
type RestLiMethod ¶
type RestLiMethod string
RestLiMethod - LinkedIn Rest.Li method type
const ( Get RestLiMethod = "GET" BatchGet RestLiMethod = "BATCH_GET" GetAll RestLiMethod = "GET_ALL" Finder RestLiMethod = "FINDER" BatchFinder RestLiMethod = "BATCH_FINDER" Create RestLiMethod = "CREATE" BatchCreate RestLiMethod = "BATCH_CREATE" Update RestLiMethod = "UPDATE" BatchUpdate RestLiMethod = "BATCH_UPDATE" PartialUpdate RestLiMethod = "PARTIAL_UPDATE" BatchPartialUpdate RestLiMethod = "BATCH_PARTIAL_UPDATE" Delete RestLiMethod = "DELETE" BatchDelete RestLiMethod = "BATCH_DELETE" Action RestLiMethod = "ACTION" )
LinkedIn Rest.Li methods
type Result ¶
type Result map[string]interface{}
Result - response body from LinkedIn API call request.
type Session ¶
type Session struct {
HTTPClient HTTPClient // HTTP client to send requests
BaseURL string // set to override API base URL
LinkedInVersion string // e.g. 202404
// contains filtered or unexported fields
}
Session holds a LinkedIn session with an access token. Session should be created by App.Session.
func (*Session) AccessToken ¶
AccessToken returns current access token.
func (*Session) Context ¶
Context returns the session's context. To change the context, use `Session#WithContext`.
The returned context is always non-nil; it defaults to the background context. For outgoing LinkedIn API requests, the context controls timeout/deadline and cancellation.
func (*Session) Introspect ¶
Introspect checks the Time to Live (TTL) and status (active/expired) for the given token.
func (*Session) SetAccessToken ¶
SetAccessToken sets a new access token.
func (*Session) SetLinkedInVersion ¶ added in v0.1.1
SetLinkedInVersion overrides the default LinkedIn API version.
func (*Session) UseAuthorizationHeader ¶
func (session *Session) UseAuthorizationHeader()
UseAuthorizationHeader passes `access_token` in HTTP Authorization header.
type Token ¶
type Token struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
RefreshTokenExpiresIn int64 `json:"refresh_token_expires_in"`
Scope string `json:"scope"`
}
Token - access and refresh tokens.
type TokenData ¶
type TokenData struct {
Active bool `json:"active"`
ClientID string `json:"client_id"`
AuthorizedAt int64 `json:"authorized_at"`
CreatedAt int64 `json:"created_at"`
Status string `json:"status"`
ExpiresAt int64 `json:"expires_at"`
Scope string `json:"scope"`
AuthType string `json:"auth_type"`
}
TokenData - access and refresh token data after token inspection.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
auth
command
Package main - LinkedIn OAuth authorization code flow example.
|
Package main - LinkedIn OAuth authorization code flow example. |
|
me
command
Package main - LinkedIn HTTP GET example.
|
Package main - LinkedIn HTTP GET example. |
|
organization
command
Get list of organizations managed by the authenticated user.
|
Get list of organizations managed by the authenticated user. |
|
post
command
Fetch published posts from a LinkedIn page
|
Fetch published posts from a LinkedIn page |