# Facebook Integration via LowCodeAPI

## Overview

Facebook Graph API provides access to Facebook's social graph data, allowing developers to build applications that interact with Facebook users, pages, posts, photos, events, groups, and comments. The API supports reading and writing data, making it possible to create social media management tools, analytics dashboards, and content scheduling systems.

## Base Endpoint

```
https://api.lowcodeapi.com/facebook/
```

## Authentication

LowCodeAPI handles authentication automatically. You only need to:

1. **Sign up** at [Facebook Developers](https://developers.facebook.com/apps)
2. **Create an app** and generate an access token
3. **Connect your account** in LowCodeAPI dashboard
4. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Facebook access token from the database
- Apply it to each request
- Handle token refresh when needed

**Auth Type**: Access Token (OAuth2.0)

## API Categories

- **Social Media** - Social media platforms and content sharing APIs

## Common Endpoints

### Category: User

#### Get Current User

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/me`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/me?api_token={api_token}
```

**Description**: Get information about the current user (the authenticated user)

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `fields` | string | No | Comma-separated list of fields to retrieve (e.g., id,name,email) |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/me?fields=id,name,email,picture&api_token=YOUR_API_TOKEN"
```

**Example Response**:
```json
{
  "data": {
    "id": "123456789",
    "name": "John Doe",
    "email": "[email protected]",
    "picture": {
      "data": {
        "url": "https://platform-lookaside.fbsbx.com/..."
      }
    }
  }
}
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/user](https://developers.facebook.com/docs/graph-api/reference/user)

---

#### Get User

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/user_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/user_id?user_id={user_id}&api_token={api_token}
```

**Description**: Get information about a specific Facebook user

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `user_id` | string | Yes | The Facebook user ID to retrieve |
| `fields` | string | No | Comma-separated list of fields to retrieve |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/user_id?user_id=123456789&fields=id,name,picture&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/user](https://developers.facebook.com/docs/graph-api/reference/user)

---

#### Get Current User Feed

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/me/feed`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/me/feed?api_token={api_token}
```

**Description**: Get the current user's feed (posts from the user and their friends)

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `fields` | string | No | Comma-separated list of fields to retrieve |
| `limit` | number | No | Number of items to return (default: 25) |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/me/feed?limit=10&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/user/feed](https://developers.facebook.com/docs/graph-api/reference/user/feed)

---

#### Post to Current User Feed

**Method**: `POST` | **LowCodeAPI Path**: `/v16.0/me/feed`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/me/feed?api_token={api_token}
```

**Description**: Create a new post on the current user's feed

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `message` | string | No | The text content of the post |
| `link` | string | No | URL to attach to the post |
| `place` | string | No | Page ID of a location associated with the post |
| `tags` | string | No | Comma-separated list of user IDs tagged in the post |
| `privacy` | string | No | Privacy settings for the post |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/me/feed?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Hello from LowCodeAPI!",
    "link": "https://example.com"
  }'
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/user/feed](https://developers.facebook.com/docs/graph-api/reference/user/feed)

---

### Category: Page

#### Get Page

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/page_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/page_id?page_id={page_id}&api_token={api_token}
```

**Description**: Get information about a Facebook Page

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page_id` | string | Yes | The Facebook Page ID |
| `fields` | string | No | Comma-separated list of fields to retrieve |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/page_id?page_id=123456789&fields=id,name,about,category&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/page](https://developers.facebook.com/docs/graph-api/reference/page)

---

#### Post to Page Feed

**Method**: `POST` | **LowCodeAPI Path**: `/v16.0/page_id/feed`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/page_id/feed?page_id={page_id}&api_token={api_token}
```

**Description**: Create a post on a Facebook Page

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page_id` | string | Yes | The Facebook Page ID |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `message` | string | No | The text content of the post |
| `link` | string | No | URL to attach to the post |
| `published` | boolean | No | Whether the post should be published (default: true) |
| `scheduled_publish_time` | number | No | Unix timestamp for scheduled publishing |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/page_id/feed?page_id=123456789&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "New product announcement!",
    "link": "https://example.com/product"
  }'
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/page/feed](https://developers.facebook.com/docs/graph-api/reference/page/feed)

---

### Category: Post

#### Get Post

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/post_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id={post_id}&api_token={api_token}
```

**Description**: Get information about a specific post

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `post_id` | string | Yes | The Facebook post ID |
| `fields` | string | No | Comma-separated list of fields to retrieve |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id=123456789_987654321&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/post](https://developers.facebook.com/docs/graph-api/reference/post)

---

#### Update Post

**Method**: `POST` | **LowCodeAPI Path**: `/v16.0/post_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id={post_id}&api_token={api_token}
```

**Description**: Update an existing post

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `post_id` | string | Yes | The Facebook post ID to update |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `message` | string | No | Updated message text for the post |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id=123456789_987654321&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Updated post content"
  }'
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/post](https://developers.facebook.com/docs/graph-api/reference/post)

---

#### Delete Post

**Method**: `DELETE` | **LowCodeAPI Path**: `/v16.0/post_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id={post_id}&api_token={api_token}
```

**Description**: Delete a post

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `post_id` | string | Yes | The Facebook post ID to delete |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id=123456789_987654321&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/post](https://developers.facebook.com/docs/graph-api/reference/post)

---

### Category: Photo

#### Upload Photo to User

**Method**: `POST` | **LowCodeAPI Path**: `/v16.0/me/photos`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/me/photos?api_token={api_token}
```

**Description**: Upload a photo to the current user's photos

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `url` | string | No | URL of a photo already uploaded to the internet |
| `caption` | string | No | Caption for the photo |
| `published` | boolean | No | Whether to publish the photo (default: true) |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/me/photos?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/photo.jpg",
    "caption": "Beautiful sunset!"
  }'
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/user/photos](https://developers.facebook.com/docs/graph-api/reference/user/photos)

---

### Category: Event

#### Get Event

**Method**: `GET` | **LowCodeAPI Path**: `/v16.0/event_id`

**Full URL**:
```
https://api.lowcodeapi.com/facebook/v16.0/event_id?event_id={event_id}&api_token={api_token}
```

**Description**: Get information about a specific Facebook event

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `event_id` | string | Yes | The Facebook event ID |
| `fields` | string | No | Comma-separated list of fields to retrieve |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/event_id?event_id=123456789&fields=id,name,start_time,end_time,description&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://developers.facebook.com/docs/graph-api/reference/event](https://developers.facebook.com/docs/graph-api/reference/event)

---

## Usage Examples

### Example 1: Social Media Management Workflow

This example demonstrates posting to your Facebook feed, then retrieving and managing the post:

```bash
# Step 1: Create a new post on your feed
# The response will contain the new post ID
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/me/feed?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Check out our new blog post!",
    "link": "https://example.com/blog"
  }'

# Step 2: Retrieve the post details using the post ID returned from Step 1
# Replace POST_ID with the actual ID from the previous response (e.g., 123456789_987654321)
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/post_id?post_id=POST_ID&api_token=YOUR_API_TOKEN"

# Step 3: Get comments on the post
# Use the same POST_ID from Step 1
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/post_id/comments?post_id=POST_ID&limit=10&api_token=YOUR_API_TOKEN"

# Step 4: Reply to a comment (create a nested comment)
# Replace COMMENT_ID with an ID from the comments retrieved in Step 3
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/post_id/comments?post_id=POST_ID&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Thanks for your feedback!"
  }'
```

### Example 2: Page Management Workflow

This example shows how to manage a Facebook Page:

```bash
# Step 1: Get all pages you manage
# This returns a list of pages with their IDs
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/me/accounts?fields=id,name,category,picture&api_token=YOUR_API_TOKEN"

# Step 2: Get page details
# Replace PAGE_ID with an ID from Step 1 (e.g., 123456789)
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/page_id?page_id=PAGE_ID&fields=id,name,about,fan_count&api_token=YOUR_API_TOKEN"

# Step 3: Post to the page feed
# Use the same PAGE_ID
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/page_id/feed?page_id=PAGE_ID&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Special offer for our followers! Use code SAVE20",
    "link": "https://example.com/offer"
  }'

# Step 4: Get recent posts from the page
# Use the same PAGE_ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/page_id/posts?page_id=PAGE_ID&limit=5&api_token=YOUR_API_TOKEN"

# Step 5: Get page photos
# Use the same PAGE_ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/page_id/photos?page_id=PAGE_ID&fields=id,name,picture&limit=10&api_token=YOUR_API_TOKEN"
```

### Example 3: Event and Group Interaction

This example demonstrates working with Facebook events and groups:

```bash
# Step 1: Get your pages' events
# Replace PAGE_ID with your page ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/page_id/events?page_id=PAGE_ID&fields=id,name,start_time&api_token=YOUR_API_TOKEN"

# Step 2: Get event details
# Replace EVENT_ID with an event ID from Step 1
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/event_id?event_id=EVENT_ID&fields=id,name,description,attending_count&api_token=YOUR_API_TOKEN"

# Step 3: Get event attendees
# Use the same EVENT_ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/event_id/attending?event_id=EVENT_ID&limit=50&api_token=YOUR_API_TOKEN"

# Step 4: Get group information
# Replace GROUP_ID with a Facebook group ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/group_id?group_id=GROUP_ID&fields=id,name,description,member_count&api_token=YOUR_API_TOKEN"

# Step 5: Get group feed posts
# Use the same GROUP_ID
curl -X GET "https://api.lowcodeapi.com/facebook/v16.0/group_id/feed?group_id=GROUP_ID&limit=10&api_token=YOUR_API_TOKEN"

# Step 6: Post to group feed
# Use the same GROUP_ID
curl -X POST "https://api.lowcodeapi.com/facebook/v16.0/group_id/feed?group_id=GROUP_ID&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Hello everyone! Has anyone tried the new feature?",
    "link": "https://example.com/feature"
  }'
```

## Complete Endpoint Reference

For a complete list of all endpoints and their parameters, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/facebook/definition`
- **Official Provider Documentation**: [https://developers.facebook.com/docs/graph-api](https://developers.facebook.com/docs/graph-api)

## Rate Limits & Best Practices

Facebook has rate limits based on:
- **Token type** (User vs. Page access tokens)
- **Endpoint calls** per day
- **Complexity** of queries (multi-queries cost more)

Best practices:
- Use field filtering to request only needed data
- Implement exponential backoff for rate limit errors
- Cache data that doesn't change frequently
- Use batch requests for multiple operations

## Error Handling

Standard HTTP status codes apply:
- **200** - Success
- **400** - Bad request (invalid parameters)
- **401** - Authentication failed
- **403** - Permission denied
- **404** - Resource not found
- **429** - Rate limit exceeded
- **500** - Server error

Errors are returned in the response body with details:
```json
{
  "error": {
    "message": "Error description",
    "type": "OAuthException",
    "code": 190
  }
}
```