Hi authors, this article is dedicated to expanding the coverage of your articles. Almost every developer has a LinkedIn account, and this article is for you.
Unfortunately, the LinkedIn API doesn't allow posting publications directly as a simple user. You need to create a company for this. First of all, go to the business page and make the new company's page using this link.
You'll be redirected to the new page for the business of your page:
Fill required fields:
If you everything done is correct, you'll be redirected to the company's page:
Now, you need to go to the developer portal using link and create the new application:
Fill up all required fields and find your company:
You'll be redirected to the application page, where you must request access to two products. Without them, you won't be able to use the API.
If you click on the endpoints, you'll see available endpoints.
You have access to endpoints as a member of LinkedIn.
The next step is to verify your app:
There will be a generated link you should go to to associate your company and application.
In the last step, you need to go by the link and generate an access token:
You need to select your app and scope:
In the throws pop-up window, enter login and password to your LinkedIn account:
If everything is correct, you'll see the token. Save it.
dev.to
Go to the https://dev.to/settings/extensions and generate the key for API.
GitHub
Next, we need to add a job to the GitHub repository. I won't tell you how to create the public repository. You can find it on this site. As an example, you can also explore my repository. The workflow should contain a schedule like this.
name: "Cronjob"
on:
schedule:
- cron: '15 */6 * * *'
push:
branches:
- 'main'
In the jobs namespace, add the new job like this:
- name: Post published articles to LinkedIn
run: |
git clone https://github.com/SergKorol/PostDevToLi.git
cd PostDevToLi/PostDevToLi
dotnet build
if [ -f ../../data/posted_articles.db ]; then
cp ../../data/posted_articles.db ./bin/Debug/net8.0/
if [ $? -ne 0 ]; then
echo "Error: Failed to copy the database."
exit 1
fi
fi
dotnet restore
dotnet run --project PostDevToLi.csproj -- \
--api-key="${{ secrets.DEV_TO_API_KEY }}" \
--access-token="${{ secrets.ACCESS_TOKEN }}" \
--ago=72
- name: Copy DB to the correct folder
run: |
cp PostDevToLi/PostDevToLi/bin/Debug/net8.0/posted_articles.db ./data/posted_articles.db
I'll tell you a little bit about the application. It's a simple console application that gets three arguments. The first two are tokens to API, dev.to
, and linkenin.com
. The last argument is the hours count from the current DateTime, which we use to take and publish articles. If the article is already published, it won't published again. And the critical notice. The application takes only the last 30 published articles. You have published many articles if you haven't posted anything on LinkedIn. Some of them won't be posted on LinkedIn. The service is oriented toward regular postings on LinkedIn. In this case, you won't have any issues.
I hope the article was helpful to you. See you next week. Happy coding!
Top comments (3)
I mean, would anyone use such approach in real life? It takes a second to copy-paste url, another couple of seconds to give it a personal touch if necessary. Who would do a whole bunch of trickery just to resend a link without any context on an org page?!
(The answer is we, developers 😅 because we can…)
Why did you decide that the post is sent to the org's page? Why do you need bots when you can just post messages to Telegram or Viber? Why does Zapier or IFTTT take money for automation? Ask yourself.
Automation is not single-faced 😏 things you talk about are mostly for spammers and scammers with no credibility, so if that’s the purpose for such insane complexity perversions, that’s just lame… on the other hand, if that “just because I can…” — that’s legit, kudos 😄
Some comments have been hidden by the post's author - find out more