# MTS Social Auto Post - Troubleshooting Guide

A comprehensive guide to resolving common Facebook API integration issues.

---

## Table of Contents

1. [Error #200: Permission Denied](#error-200-permission-denied)
2. [Error: "The URL you supplied is invalid"](#error-the-url-you-supplied-is-invalid)
3. [Error #100: Nonexisting field (accounts)](#error-100-nonexisting-field-accounts)
4. [Error #10: pages_read_engagement permission required](#error-10-pages_read_engagement-permission-required)
5. [Token Types Explained](#token-types-explained)
6. [App Development vs Live Mode](#app-development-vs-live-mode)
7. [Business Manager Pages Not Showing in me/accounts](#business-manager-pages-not-showing)
8. [Token Refresh & Expiration](#token-refresh--expiration)
9. [Test Connection Works But Posting Fails](#test-connection-works-but-posting-fails)

---

## Error #200: Permission Denied

### Error Message
```
(#200) If posting to a group, requires app being installed in the group, and either publish_to_groups permission with user token, or both pages_read_engagement and pages_manage_posts permission with page token; If posting to a page, requires both pages_read_engagement and pages_manage_posts as an admin with sufficient administrative permission
```

### Causes
1. **Wrong token type** - Using a User Token or System User Token instead of a Page Access Token
2. **Missing permissions** - Token doesn't have required permissions
3. **App in Development mode** - App not published/live yet
4. **Token generated before app went Live** - Permissions not properly attached

### Solutions

#### Solution 1: Verify You Have a Page Token (Not User Token)

1. Go to [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
2. Paste your token in the Access Token field
3. Query: `me?fields=id,name`
4. Click **Submit**
5. Check the response:

| Response Name | Token Type | Can Post? |
|---------------|------------|-----------|
| Your Page name (e.g., "My Business") | ✅ Page Token | Yes |
| Your personal name (e.g., "John Doe") | ❌ User Token | No |
| System User name (e.g., "API Bot") | ❌ System User Token | No |

**If you see your personal name or a system user name, you need to get the actual Page Token.**

#### Solution 2: Get the Correct Page Token

1. Go to [Business Manager System Users](https://business.facebook.com/settings/system-users)
2. Click on your System User (e.g., "API Bot")
3. Click **Generate new token**
4. Select your Facebook App
5. **Important:** Check these permissions:
   - ✅ `pages_show_list`
   - ✅ `pages_read_engagement`
   - ✅ `pages_manage_posts`
6. Click **Generate token** and copy it
7. Go to [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
8. Paste the System User token
9. Query: `me/accounts`
10. Click **Submit**
11. In the response, find your page and copy its `access_token`
12. **Use THIS token in your plugin settings** - this is the actual Page Token

#### Solution 3: Make Sure App is Live

See [App Development vs Live Mode](#app-development-vs-live-mode) section below.

---

## Error: "The URL you supplied is invalid"

### Error Message
```
Failed - The url you supplied is invalid
```

### Cause
Facebook cannot validate **localhost URLs**. When testing on a local development environment (e.g., `http://localhost:8080/my-post/`), the plugin sends this URL to Facebook, which Facebook rejects because it cannot access or scrape localhost.

### Solutions

#### Solution 1: Test on a Live Site (Recommended)
Deploy your WordPress site to a live server with a real domain (e.g., `https://yourdomain.com`). Facebook can then validate and scrape your URLs properly.

#### Solution 2: Remove URL from Post Template (Temporary Fix)
1. Go to **Social Auto Post** → **Settings**
2. Find the **Post Template** option
3. Change from:
   ```
   {title}

   {excerpt}

   {url}
   ```
   To:
   ```
   {title}

   {excerpt}

   #yourbusiness #yourhashtags
   ```
4. Save and test - posts will go through without links

#### Solution 3: Use ngrok for Local Testing
1. Download and install [ngrok](https://ngrok.com/)
2. Run: `ngrok http 8080` (replace 8080 with your local port)
3. Copy the https URL ngrok provides
4. Update your WordPress Site URL temporarily for testing

---

## Error #100: Nonexisting field (accounts)

### Error Message
```
(#100) Tried accessing nonexisting field (accounts) on node type (Page)
```

### Cause
You're querying `me/accounts` with a **Page Token**. Page tokens don't have "accounts" - only User Tokens and System User Tokens do.

### What This Actually Means
**Good news!** If you see this error, you likely already have a Page Token. The token is correct for posting.

### Solution
Don't query `me/accounts`. Instead, test posting directly:

1. In Graph API Explorer, change **GET** to **POST**
2. Enter endpoint: `YOUR_PAGE_ID/feed`
3. Add parameter: `message` = `Test post`
4. Click **Submit**

If it works, use this token in your plugin settings.

---

## Error #10: pages_read_engagement permission required

### Error Message
```
(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature.
```

### Cause
The token was generated **before** the app was published (went Live). Tokens generated in Development mode don't carry full permissions even after the app goes Live.

### Solution
**Regenerate the token after the app is Live:**

1. First, make sure your app is Live (see [App Development vs Live Mode](#app-development-vs-live-mode))
2. Go to [Business Manager System Users](https://business.facebook.com/settings/system-users)
3. Click on your System User
4. Click **Generate new token** (create a fresh one)
5. Select your app and check all required permissions
6. Generate and get the new Page Token via `me/accounts`
7. Update your plugin settings with the new token

---

## Token Types Explained

Understanding Facebook's token types is crucial for successful integration.

### The Three Token Types

| Token Type | Identifies As | Can Post to Page? | How to Get |
|------------|---------------|-------------------|------------|
| **User Token** | Your personal name | ❌ No | Graph API Explorer with "User Token" selected |
| **System User Token** | System user name (e.g., "API Bot") | ❌ No | Business Manager → System Users → Generate Token |
| **Page Access Token** | Your Page name | ✅ Yes | Query `me/accounts` with System User Token |

### Token Hierarchy

```
System User Token
        │
        ▼
   me/accounts query
        │
        ▼
  Page Access Token  ←── Use this for posting!
```

### How to Verify Your Token Type

1. Go to [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
2. Paste your token
3. Query: `me?fields=id,name`
4. The `name` field tells you the token type:
   - Page name = Page Token ✅
   - Personal name = User Token ❌
   - "API Bot" or similar = System User Token ❌

---

## App Development vs Live Mode

### Why This Matters
Apps in **Development mode** have restricted permissions:
- Only users with app roles can use it
- Some permissions don't work fully
- Tokens may not have all scopes

### How to Check App Mode

1. Go to [Facebook Developers](https://developers.facebook.com/apps/)
2. Select your app
3. Look at the left sidebar for **"Publish"**
4. Check if it says **"Unpublished"** or **"Published"**

### How to Publish Your App

1. In your app dashboard, click **"Publish"** in the left sidebar
2. Review the checklist - complete any required items:
   - App settings configured ✅
   - Use cases added ✅
   - Privacy policy URL ✅
3. Click the **"Publish"** button (bottom right)
4. Confirm publication

### After Publishing
**Important:** Regenerate your tokens after the app goes Live. Old tokens from Development mode may not work correctly.

---

## Business Manager Pages Not Showing

### Problem
When you query `me/accounts` with a User Token, your Facebook Page doesn't appear in the list.

### Cause
Pages owned by a **Business Manager** (Business Portfolio) don't show up in personal account queries. They exist in a separate ownership structure.

### Your Page Ownership Structure
```
Your Personal Facebook Account
    │
    └── Pages you personally own (show in me/accounts)

Business Manager / Business Portfolio
    │
    └── Pages owned by business (DON'T show in personal me/accounts)
          │
          └── Your Page (e.g., "Monir Tech Solutions")
```

### Solution: Use System User Tokens

1. Go to [Business Manager Settings](https://business.facebook.com/settings)
2. Navigate to **Users** → **System Users**
3. Create a System User if you don't have one:
   - Click **Add**
   - Name: "API Bot" (or any name)
   - Role: **Admin**
4. Assign assets to the System User:
   - Click the System User → **Assign assets**
   - Add your **Page** with **Full control**
   - Add your **App** with **Full control**
5. Generate a token for this System User
6. Query `me/accounts` - now your page will appear!

---

## Token Refresh & Expiration

### Token Lifespans

| Token Type | Typical Duration | Notes |
|------------|------------------|-------|
| Short-lived | ~1-2 hours | Generated via Graph API Explorer |
| Long-lived | ~60 days | Extended via API or System User |
| System User (never expire) | Indefinite | Set "Never" when generating |

### How to Generate a Non-Expiring Token

1. Go to Business Manager → System Users
2. Click your System User → Generate Token
3. Set **Token Expiration** to **"Never"**
4. Generate and extract the Page Token

### Signs Your Token Has Expired

- Posts suddenly start failing after working
- Error messages about invalid or expired tokens
- "Session has expired" errors

### Solution
Regenerate a fresh token following the [Get the Correct Page Token](#solution-2-get-the-correct-page-token) steps above.

---

## Test Connection Works But Posting Fails

### Symptom
The "Test Connection" button shows success (green), but actual posts fail.

### Causes

1. **Test Connection only verifies basic API access**, not posting permissions
2. Token might have read permissions but not write permissions
3. Page might have posting restrictions enabled

### Solution

1. **Test posting directly in Graph API Explorer:**
   - Go to [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
   - Paste your Page Token
   - Change GET to **POST**
   - Endpoint: `YOUR_PAGE_ID/feed`
   - Add parameter: `message` = `Test post`
   - Submit

2. **If it fails**, follow the [Error #200](#error-200-permission-denied) troubleshooting steps

3. **If it works in Explorer but not in plugin**, the token in your plugin settings may be different or incorrectly saved. Re-copy and paste the working token.

---

## Quick Diagnostic Checklist

Run through this checklist when troubleshooting:

- [ ] **App is Live** (not in Development mode)
- [ ] **Token is a Page Token** (not User or System User token)
- [ ] **Token was generated AFTER app went Live**
- [ ] **Required permissions are checked** when generating token:
  - [ ] `pages_show_list`
  - [ ] `pages_read_engagement`  
  - [ ] `pages_manage_posts`
- [ ] **System User has page assigned** with Full Control
- [ ] **Testing on live site** (not localhost)
- [ ] **Token hasn't expired**

---

## Still Need Help?

If you've tried all the above solutions and still have issues:

1. **Check the Post Log** in the plugin for specific error messages
2. **Test in Graph API Explorer** to isolate if it's a token/API issue or plugin issue
3. **Contact Support** at info@monirtechsolutions.com with:
   - The exact error message
   - Screenshots of your app settings
   - Steps you've already tried

---

*Last updated: January 2026*
