golinkedinapi

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 10 Imported by: 0

README

linkedin-api GoDoc

NOTE:

This package is for the V1 API which has been deprecated and is pending removal. I don't currently have any plans on supporting V2, although that may change in the future. Any V2 support would be a major breaking change, and as such the state of the API would be subject to massive change, as well as dropping V1 support.

This project functions as a pure Go interface for Linkedin's v1 REST API. Currently, this provides a lightweight, documented interface to get a user's posts & profile data into a native marshallable Go struct. Requests are made secure by using OAuth2.0 authenticated requests to LinkedIn's servers.

This was my first project written in Go, and so I'd love to hear your thoughts!

This currently only supports GET requests.

Installation

go get -t github.com/johnaoss/linkedin-api

That's it!

Examples

I haven't tested this with other routing packages, but this does indeed work for any program using gorilla/mux for routing purposes.

Setting up the configurations

import api "github.com/johnaoss/linkedin-api"

func main() {
    permissions := []string{"r_basicprofile"}
    clientID := "myID"
    clientSecret := "hush"
    redirectURL := "https://example.com/totallyvalidauth"
    api.InitConfig(permissions, clientID, clientSecret, redirectURL)
}

Getting a user's login url (includes state)
import api "github.com/johnaoss/linkedin-api"

func loginHandler(w http.ResponseWriter, r *http.Request) {
    login := api.GetLoginURL(w,r)
    html := "Your login is <a href=\"" + login + "\">Login here!</a>"
    w.Write([]byte(html))
}
Getting a user's data
import api "github.com/johnaoss/linkedin-api"

// this handles the authorized redirect URL as specified in the Linkedin developer console
func authHandler(w http.ResponseWriter, r *http.Request) {
    userData := api.GetProfileData(w,r)
    html := "Your name is is " userData.FirstName + " " + userData.LastName
    w.Write([]byte(html))
}
Sharing a comment (UNTESTED)
import api "github.com/johnaoss/linkedin-api"

func sharePost(w http.ResponseWriter, r *http.Request) {
    vis := VisibilityStruct{Code: "anyone"}
    post := &api.Post{Visibility: vis, Comment: "This is a comment"}
    resp, err := api.SharePost(post,w,r)
    if err != nil {
        w.Write([]byte("Something went wrong!"))
    } else {
        w.Write([]byte("Your post was successfully shared!"))
    }
}

Limitations

This currently services only the non-partnered content as LinkedIn does not have any means of open-source developers to reliably acquire this data. Aside from that, if there are any bugs please feel free to get in touch with either an issue or an e-mail!

License

MIT Licensed, check the LICENSE.md file for more details.

TODO

  1. Proper testing of functions that require a router.
  2. POST features
  3. Full Linkedin Partner features (if possible)
  4. More info on current-share
  5. Clean up this code (was my first Go project after all)
  6. Work on v2 of this project!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoginURL

func GetLoginURL(w http.ResponseWriter, r *http.Request) string

GetLoginURL provides a state-specific login URL for the user to login to. CAUTION: This must be called before GetProfileData() as this enforces state.

func InitConfig

func InitConfig(permissions []string, clientID string, clientSecret string, redirectURL string)

InitConfig initializes the config needed by the client. permissions is a string of all scopes desired by the user.

func SharePost

func SharePost(post *Post, w http.ResponseWriter, r *http.Request) (*http.Response, error)

SharePost is the primary method of sharing a post.

Types

type ContentStruct

type ContentStruct struct {
	Title             string `json:"title,omitempty"`
	Description       string `json:"description,omitempty"`
	SubmittedURL      string `json:"sumbitted-url,omitempty"`
	SubmittedImageURL string `json:"submitted-image-url,omitempty"`
}

ContentStruct represents a collection of fields describing the shared content.

type LinkedinProfile

type LinkedinProfile struct {
	// ProfileID represents the Unique ID every Linkedin profile has.
	ProfileID string `json:"id"`
	// FirstName represents the user's first name.
	FirstName string `json:"first_name"`
	// LastName represents the user's last name.
	LastName string `json:"last-name"`
	// MaidenName represents the user's maiden name, if they have one.
	MaidenName string `json:"maiden-name"`
	// FormattedName represents the user's formatted name, based on locale.
	FormattedName string `json:"formatted-name"`
	// PhoneticFirstName represents the user's first name, spelled phonetically.
	PhoneticFirstName string `json:"phonetic-first-name"`
	// PhoneticFirstName represents the user's last name, spelled phonetically.
	PhoneticLastName string `json:"phonetic-last-name"`
	// Headline represents a short, attention grabbing description of the user.
	Headline string `json:"headline"`
	// Location represents where the user is located.
	Location Location `json:"location"`
	// Industry represents what industry the user is working in.
	Industry string `json:"industry"`
	// CurrentShare represents the user's last shared post.
	CurrentShare string `json:"current-share"`
	// NumConnections represents the user's number of connections, up to a maximum of 500.
	// The user's connections may be over this, however it will not be shown. (i.e. 500+ connections)
	NumConnections int `json:"num-connections"`
	// IsConnectionsCapped represents whether or not the user's connections are capped.
	IsConnectionsCapped bool `json:"num-connections-capped"`
	// Summary represents a long-form text description of the user's capabilities.
	Summary string `json:"summary"`
	// Specialties is a short-form text description of the user's specialties.
	Specialties string `json:"specialties"`
	// Positions is a Positions struct that describes the user's previously held positions.
	Positions Positions `json:"positions"`
	// PictureURL represents a URL pointing to the user's profile picture.
	PictureURL string `json:"picture-url"`
	// EmailAddress represents the user's e-mail address, however you must specify 'r_emailaddress'
	// to be able to retrieve this.
	EmailAddress string `json:"email-address"`
}

LinkedinProfile is used within this package as it is less useful than native types.

func GetProfileData

func GetProfileData(w http.ResponseWriter, r *http.Request) (*LinkedinProfile, error)

GetProfileData gather's the user's Linkedin profile data and returns it as a pointer to a LinkedinProfile struct. CAUTION: GetLoginURL must be called before this, as GetProfileData() has a state check.

type Location

type Location struct {
	UserLocation string
	CountryCode  string
}

Location specifies the users location

type Position

type Position struct {
	// ID represents a unique ID representing the position
	ID string
	// Title represents a user's position's title, for example Jeff Bezos's title would be 'CEO'
	Title string
	// Summary represents a short description of the user's position.
	Summary string
	// StartDate represents when the user's position started.
	StartDate string
	// EndDate represents the user's position's end date, if any.
	EndDate string
	// IsCurrent represents if the position is currently held or not.
	// If this is false, EndDate will not be returned, and will therefore equal ""
	IsCurrent bool
	// Company represents the Company where the user is employed.
	Company PositionCompany
}

Position represents a job held by the authorized user.

type PositionCompany

type PositionCompany struct {
	// ID represents a unique ID representing the company
	ID string
	// Name represents the name of the company
	Name string
	// Type represents the type of the company, either 'public' or 'private'
	Type string
	// Industry represents which industry the company is in.
	Industry string
	// Ticker represents the stock market ticker symbol of the company.
	// This will be blank if the company is privately held.
	Ticker string
}

PositionCompany represents a company that is described within a user's Profile. This is different from Company, which fully represents a company's data.

type Positions

type Positions struct {
	// contains filtered or unexported fields
}

Positions represents the result given by json:"positions"

type Post

type Post struct {
	Content    ContentStruct    `json:"content,omitempty"`
	Comment    string           `json:"comment"`
	Visibility VisibilityStruct `json:"visibility"`
}

Post represents a post that one shares on a Linkedin profile, not a POST request. To validate posts, call isValidPost() on one.

type VisibilityStruct

type VisibilityStruct struct {
	// Code is the only field specified in the documentation.
	// must be either "anyone" or "connections-only"
	Code string `json:"code"`
}

VisibilityStruct represents the visibility information about the shared post.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL