# LinkedIn API Setup Guide

This guide provides step-by-step instructions for setting up LinkedIn API integration for the Social Media Management System.

---

## Table of Contents

1. [Overview](#overview)
2. [Prerequisites](#prerequisites)
3. [LinkedIn Developer Portal Setup](#linkedin-developer-portal-setup)
4. [Environment Configuration](#environment-configuration)
5. [OAuth Redirect URI Configuration](#oauth-redirect-uri-configuration)
6. [Permissions & Scopes](#permissions--scopes)
7. [Webhook Configuration (Optional)](#webhook-configuration-optional)
8. [Development vs Production](#development-vs-production)
9. [Troubleshooting](#troubleshooting)

---

## Overview

**API Version:** RestLi 2.0 (Version 202411)
**Base URL:** `https://api.linkedin.com/rest`
**Auth URL:** `https://www.linkedin.com/oauth/v2/authorization`
**Token URL:** `https://www.linkedin.com/oauth/v2/accessToken`

### Features Supported
- Fetch organization posts
- Read and manage comments on organization posts
- Reply to comments as the organization
- Webhook support for real-time comment notifications

---

## Prerequisites

- A LinkedIn account with admin access to a LinkedIn Company/Organization Page
- Access to [LinkedIn Developer Portal](https://www.linkedin.com/developers/)
- HTTPS-enabled server for production (required for redirect URIs)

---

## LinkedIn Developer Portal Setup

### Step 1: Create a New App

1. Navigate to [LinkedIn Developer Portal](https://www.linkedin.com/developers/)
2. Click **"Create App"**
3. Fill in the required details:
   - **App Name:** Your application name (e.g., "PX360 Social Manager")
   - **LinkedIn Page:** Select your company/organization page
   - **Privacy Policy URL:** Your privacy policy URL
   - **App Logo:** Upload your app logo (required for review)
4. Click **"Create App"**

### Step 2: Request API Products

1. In your app dashboard, go to **"Products"** tab
2. Request access to the following products:
   - **Marketing API** (for posts and comments management)
   - **Share on LinkedIn** (for posting content)
   - **Sign In with LinkedIn** (optional, for user authentication)

3. Some products require LinkedIn approval. Submit a detailed use case explaining:
   > "We are building a Social Media Management Tool that allows organizations to manage and respond to comments on their LinkedIn posts from a centralized dashboard. This helps community managers respond faster and maintain engagement with their audience."

### Step 3: Get Credentials

1. Go to **"Auth"** tab in your app dashboard
2. Copy the following values:
   - **Client ID** → This is your `LINKEDIN_CLIENT_ID`
   - **Client Secret** → Click "Show" to reveal → This is your `LINKEDIN_CLIENT_SECRET`
