This repository contains PowerShell scripts and instructions for creating an Azure Function that automatically posts images as LinkedIn posts.
Before you can use the scripts in this repository, you need to create a LinkedIn app and obtain the necessary credentials. Follow these steps:
- Go to the LinkedIn Developers portal and sign in with your LinkedIn account.
- Click "Create app" and fill in the required information.
- After creating the app, go to the "Auth" tab and note down the "Client ID" and "Client Secret."
- In the same tab, add the necessary redirect URI for your app. This URI will be used to receive the authorization code during the OAuth 2.0 flow.
PostToLinkedIn/
│
├─ PostImageFunction/
│ ├─ function.json
│ └─ run.ps1
│
└─ README.md
PostImageFunction/
: This folder contains the Azure Function code and configuration.function.json
: This file defines the function's bindings and settings, including the Timer trigger configuration.run.ps1
: This PowerShell script contains the code that will be executed by the Azure Function.
README.md
: This file provides instructions and information about the project.
Follow these steps to set up a Timer-triggered Azure Function using the provided PowerShell script:
- Create an Azure Functions App in the Azure portal. Make sure to select "PowerShell Core" as the runtime stack.
- Create a Timer-triggered Function with a daily schedule (use the CRON expression
0 0 * * *
). - Use the provided
run.ps1
andfunction.json
files from thePostImageFunction
folder for your Azure Function. - Store the "Client ID," "Client Secret," and "Redirect URI" in the Function App's "Configuration" section as environment variables or use Azure Key Vault to securely store them.
- Use the
Generate-LinkedInAuthUrl.ps1
script to create the LinkedIn authorization URL. ReplaceYOUR_APP_CLIENT_ID
andYOUR_REDIRECT_URI
with your app's client ID and redirect URI. - Navigate to the generated authorization URL in your web browser, log in, and grant the required permissions.
- Copy the
code
parameter from the redirected URL. - Use the provided PowerShell script to exchange the authorization code for an access token. Store the access token securely in the Function App's "Configuration" section or use Azure Key Vault.
The run.ps1
script in the PostImageFunction
folder is designed to post images as LinkedIn posts. Update the script to include the logic for fetching the desired images or use a predefined list of image URLs.
To post an image, you need to use LinkedIn's API to upload the image first, and then use the returned asset URN to create the post. The provided run.ps1
script demonstrates how to do this.
To automatically deploy changes from a GitHub repository to your Azure Function, follow these steps:
- Prepare your GitHub repository, ensuring that it contains the
run.ps1
andfunction.json
files in a folder named after your function (e.g.,PostImageFunction
). - In the Azure portal, go to your Function App, and click "Deployment Center" under the "Deployment" section.
- Choose "GitHub" as your source control provider and