Utility to share Linkedin posts using the Linkedin Marketing API
Project description
LinkedIn Posts
Utility to share LinkedIn posts using the LinkedIn Marketing API
Made easy to use in Python.
Installation and Setup
Install with pip
python -m pip install linkedin-posts
Generate LinkedIn's Access Token
The quickest way to get an Access Token is by using the LinkedIn Token generator tool
Usage
Share a post
By the time I am writing this sentence, this is the most useful function of this package.
Share a post by using the function share_post
with some
arguments.
from linkedin_posts.posts import share_post
response = share_post(
"<HERE YOUR ACCESS TOKEN>",
comment="publishing a post",
author_type="organization",
author_id="71513925",
)
# Do something with your response object r (http.client.HttpResponse)
# Interesting parameters to check:
# response.getheader("x-restli-id") will return the LinkedIn Post ID
# response.code will return 201 if request proccessed correctly
...
Delete a post
Deleting a post is very straightforward.
Just just need the access token and pass the LinkedIn Post ID.
from linkedin_posts.posts import delete_post
response = delete_post("<HERE YOUR ACCESS TOKEN>", "urn:li:share:7104319981684674560")
# response.code will return 204 if request proccessed correctly
Create a poll post
It is possible to share a post with a poll by using the following code:
from linkedin_posts.polls import share_poll
response = share_poll(
"<HERE YOUR ACCESS TOKEN>",
comment="Hello, this is just a test...",
poll_question="Is this is a nice poll?",
poll_options=["Yes", "No", "I do not care"],
author_type="organization",
author_id="71513925",
)
# do something with response if you need to!
Now go to your LinkedIn page and check your published poll!
Post with media
To create a post with a nice picture you can use this code.
# upload a image
upload_request, image_urn = upload_image(
"<HERE YOUR ACCESS TOKEN>",
file="img/nicecv.jpg",
author_type=author_type,
author_id=author_id,
)
# create a post with the uploaded image
share_post_with_media(
"<HERE YOUR ACCESS TOKEN>",
comment="Do you like this nice cv?",
author_type=author_type,
author_id=author_id,
media_id=image_urn
)
And voilà. Here is your post!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file linkedin-posts-0.0.12.tar.gz
.
File metadata
- Download URL: linkedin-posts-0.0.12.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/42.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd2748a2602c1f1c21074d4fd651a7a64dfd2e74fb83f6b1cdaffc2e93ca258 |
|
MD5 | cd930cb0793cb76207d55513d709f1ff |
|
BLAKE2b-256 | bd01ff2659081afd1ca820f54b5bf57bf30d955625e7a37e97262eb452133d58 |
File details
Details for the file linkedin_posts-0.0.12-py3-none-any.whl
.
File metadata
- Download URL: linkedin_posts-0.0.12-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/42.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d17321196192ef130d735cb45da37a0d68f60b04e677a1c28ac40d6dea9f017b |
|
MD5 | 1a04d70ed6c43d704bc48f3358699545 |
|
BLAKE2b-256 | 83b747c0fb672d6e6d90107a4426e520f0d46ebcf77c137836efc9e56145c202 |