analyse linkedin R

Analyze LinkedIn with R

Rplot

Some time ago I saw an interesting post in a R related group on LinkedIn. It was from Michael Piccirilli and he wrote something about his new package Rlinkedin. I was really impressed by his work and so I decided to write a blog post about it.

Get the package

The package is currently just available via GitHub. But thanks to devtools it is not a problem to install it.

Authenticate with LinkedIn

In the next step we have to connect to the LinkedIn API via oAuth 2.0. You have two possibilities in the Rlinkedin package.

You can just use

to use a default API key for getting LinkedIn data.

Or:

You can use your own application and application credentials to connect to the API.

Therefore you have to create an application on  LinkedIn. Go on https://www.linkedin.com/secure/developer and log in with your LinkedIn account. Then click on “Add new Application”.

add_new

On the next page you can see app settings. Just set them as you can see on the following screenshots:

app_setting1 app_setting2

 

Then click on “Add application” and you get forwarded to your app´s credentials. Switch back to R and set the following variables:

Then you can authenticate with:

After a successful authentication you start to get some data.

 

Analyze LinkedIn with R

Michael created a nice overview of the different functions on the package´s GitHub page. So I will just show you here a small sample analysis.

First, lets download all your connections with:

This creates a data frame with all available information about your connections. For our analysis we will get the column “industry” which is the industry the person is working in. We will use it to create a small word cloud.

We will then transform this text with some standard word cloud to a nice looking industry overview:

This will create a word cloud like the following:

Rplot

 

Julian Hillebrand

During my time at university and learning about the basics of economics I started heavily exploring the possibilities and changes caused by digital disruptions and the process of digital transformation, whereby I focused on the importance of data and data analytics and combination with marketing and management.
My personal focus of interest lies heavily on technology, digital marketing and data analytics. I made early acquaintance with programming and digital technology and never stop being interested in following the newest innovations.

I am an open, communicative and curious person. I enjoy writing, blogging and speaking about technology.

  • Pingback: r links | Graph computing for the Arts()

  • Pingback: Distilled News | Data Analytics & R()

  • Pingback: Analyze This! Analyzing LinkedIn using R | n!Factorial Analytical Sciences()

  • Anil Kumar

    Great tutorial,
    after the data get into data frame can i able to perform any analytics of my use case .What type of use cases can be possible after getting data into data frame .can u suggest me 2 or 3 use cases ?
    Can u give more tutorials on that ,how can we use any sentimental analytics using the data that i loaded from Linkedin.?
    Thanks ,
    Anil Kumar

    • Hey
      please take a look about sentiment analysis on twitter data. This should give you a good starting point as you can easily modify it to use it for LinkedIn data.

      Regards

  • Mikkel

    Hi there Julian

    I’m totally new with R, and I get an error while trying to process the last long segment of code. The error shows up like this:

    > clean_text = clean.text(text)
    > tweet_corpus = Corpus(VectorSource(clean_text))
    Error: could not find function “Corpus”
    >
    > tdm = TermDocumentMatrix(tweet_corpus, control = list(removePunctuation = TRUE,stopwords = stopwords(“english”), removeNumbers = TRUE, tolower = TRUE))
    Error: could not find function “TermDocumentMatrix”
    >
    > #install.packages(c(“wordcloud”,”tm”),repos=”http://cran.r-project.org”)
    >
    > library(wordcloud)
    Error in library(wordcloud) : there is no package called ‘wordcloud’
    > m = as.matrix(tdm) #we define tdm as matrix
    Error in as.matrix(tdm) : object ‘tdm’ not found
    > word_freqs = sort(rowSums(m), decreasing=TRUE) #now we get the word orders in decreasing order
    Error in is.data.frame(x) : object ‘m’ not found
    > dm = data.frame(word=names(word_freqs), freq=word_freqs) #we create our data set
    Error in data.frame(word = names(word_freqs), freq = word_freqs) :
    object ‘word_freqs’ not found
    > wordcloud(dm$word, dm$freq, random.order=FALSE, colors=brewer.pal(8, “Dark2”)) #and we visualize our data
    Error: could not find function “wordcloud”
    >

    Am I missing some packages or something in my R-setup?

  • Mikkel

    Never mind!

    I just had to remove the “#” from the “install.packages(c)….” line in order to install the correct packages. Awesome tutorial btw. I got a nice looking result after a bit of trial and error 🙂

    • Hey sorry for the late answer. But thanks for your kind words.

      Regards

  • Pingback: R software and data visualization | Unstable Textuality Research()

  • jorge del rio

    Julian, is it possible to download the network from other person? i.e., visualize the network of a friend? Thanks!

  • Maggi

    Hi, I downloaded Rlinkedin package
    package ‘XML’ successfully unpacked and MD5 sums checked
    package ‘httpuv’ successfully unpacked and MD5 sums checked
    package ‘Rlinkedin’ successfully unpacked and MD5 sums checked

    But getting the following error

    > in.auth <- inOAuth()
    Error: could not find function "inOAuth"

    • Hey Maggi,
      did you use
      require(Rlinkedin)
      before calling the inOAuth() function?

      Regards

  • I used to be able to connect about year and half ago with OAuth1.0. Tried using my app using OAuth2.0 but nothing opens up on localhost:1410 I get the Page not found error

    Has anything changed from LinedIn side that would cause it to stop working ?

    Thanks for the post

    • thanks for your comment Rahul. I will take a look at it.

      • Pankaj

        Do we have any updates on this error? Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission) :

        client error: (403) Forbidden

  • This is the error I am getting

    Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission) :
    client error: (403) Forbidden

  • Wilbur

    I am getting the “webpage not available” error when I try to authenticate via OAuth2.0, any solution to this?

    • Julian Hillebrand

      Hey
      could you please show me the exact code you used?

      Regards

  • Swarnava Mitra

    I keep getting the error Firefox can’t establish a connection to the server at localhost:1410.

    • Julian Hillebrand

      Hey
      could you please show me the exact code you use?

      Regards

  • Anvitha Ra

    I tried using getMyConnections(in.auth) in Rstudio but ended up with below error:

    Error in x.list[sapply(x.list, is.list)] <- NA :

    invalid subscript type 'list'

    Can someone pls help??

    • Same error here. I am just starting with R and have no clue. Have you found a workaround?

  • wiseyoungbuck

    I was excited to find this, but has anyone used it since LinkedIn closed their API? It seems like it has a lot more limited functionality.

  • ayush

    Hi, Anyone is still able to use this package. i am not able to work around on this package as most of the function are not working due to some limited access by linkedin.

    Is there any other way to get the access of group post using R?

  • sas

    Hi
    I am using RStudio in the official docker container.
    When I try to connect to linkedin as it is described above, but I am getting error.
    I getting to: “Sign in to LinkedIn and allow access:”, but when it want to forward the page not accessible.

    I am trying with
    http://localhost:1410
    and also
    http://172.17.0.2:1410
    setup, even I added both just in case…
    This is what I can not access..
    http://172.17.0.2:1410/?oauth_token=78–d05113c4-721d-40cd-855b-70d35dccdab2&oauth_verifier=57445

    Any idea how to run this from inside docker?
    Thanx

  • Mayi Olga

    Hi, is it possible to extract information from a company? It’s that I have a job on some universities in this social network

    • pero magdy

      kindly I am working in similar research can you please send me an your mail to p.magdytab@gmail.com if you have any social network dataset or have any method to download it from any network
      Thanks