{
  "id": "-FEhdbBR-54aRN5lJr5rN",
  "name": "Analyze All Facebook Post Comments",
  "tags": [],
  "nodes": [
    {
      "id": "edd58237-a0f1-462c-b1c6-414d216a8f33",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1488,
        160
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d42dac6b-6de8-4e69-9a46-2a1ff588f8a1",
      "name": "Call 'Facebook'",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        -256,
        -128
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9def7b4f-d741-43de-a080-205fe5d1303d",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -1488,
        624
      ],
      "parameters": {
        "inputSource": "passthrough"
      },
      "typeVersion": 1.1
    },
    {
      "id": "edf74742-4a6c-422b-a403-a91a4803e1fd",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -176,
        624
      ],
      "parameters": {
        "amount": 3
      },
      "typeVersion": 1.1
    },
    {
      "id": "682d7853-7623-4e6c-b84c-9c1a2f21a374",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -752,
        752
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "29f5c270-146f-4d9d-ad9f-38784bd9b364",
      "name": "Sentiment Analysis",
      "type": "@n8n/n8n-nodes-langchain.sentimentAnalysis",
      "position": [
        -816,
        496
      ],
      "parameters": {
        "options": {
          "categories": "Positive, Neutral, Negative",
          "systemPromptTemplate": "You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON."
        },
        "inputText": "={{ $json.message || 'empty' }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "6edda9f7-6f4c-4bd4-867a-228b8f9dbafc",
      "name": "Set Fb post ID",
      "type": "n8n-nodes-base.set",
      "position": [
        -1264,
        160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4ef3030f-bb6a-45df-81ef-c97dafdf75e7",
              "name": "post_id",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "64b9d159-ebdd-4e37-94cc-8033b905a305",
      "name": "Get Fb Post",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        -1040,
        160
      ],
      "parameters": {
        "node": "={{ $json.post_id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,message,created_time,permalink_url, attachments{title,description,media_type,url,unshimmed_url}"
              }
            ]
          }
        },
        "graphApiVersion": "v21.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0dd54510-fc0f-443e-9b89-124ff562af6d",
      "name": "Get Fb comments",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        -816,
        160
      ],
      "parameters": {
        "edge": "comments",
        "node": "={{ $('Set Fb post ID').item.json.post_id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,from,message,created_time,comment_count"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "order",
                "value": "reverse_chronological"
              },
              {
                "name": "after",
                "value": "={{$json.after || \"\"}}"
              },
              {
                "name": "summary",
                "value": "true"
              }
            ]
          }
        },
        "graphApiVersion": "v21.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "046776ad-1b93-4785-9abd-7999e0917975",
      "name": "Next page?",
      "type": "n8n-nodes-base.if",
      "position": [
        -592,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "94888acd-7f72-4765-8d05-3f7644e0647a",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Get Fb comments').item.json.paging.cursors.after }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9be30fb1-20b7-4716-b6d7-9e0f2274cfc6",
      "name": "Get next comments page",
      "type": "n8n-nodes-base.set",
      "position": [
        -256,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d09aa72b-3c2c-4c99-b48d-20f1c4a148cd",
              "name": "after",
              "type": "string",
              "value": "={{ $json.paging.cursors.after }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "32b8cc8d-f166-4883-a88b-0046bbe5e539",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -1264,
        624
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "50744f4c-8ee6-42f1-a4fb-c5daeebb3b83",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -1040,
        624
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "480fda4b-b4f6-4018-b5ad-3d5623ece78e",
      "name": "Add comment",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -464,
        496
      ],
      "parameters": {
        "columns": {
          "value": {
            "COMMENT": "={{ $json.message }}",
            "SENTIMENT": "={{ $json.sentimentAnalysis.category }}",
            "COMMENT ID": "={{ $json.id }}"
          },
          "schema": [
            {
              "id": "POST ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "POST ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "COMMENT ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "COMMENT ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "COMMENT",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "COMMENT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SENTIMENT",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "SENTIMENT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "COMMENT ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xMLAtBgSdxh7Cc--J6fExGb2ul48QTvN-KgGitEGgZw/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xMLAtBgSdxh7Cc--J6fExGb2ul48QTvN-KgGitEGgZw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xMLAtBgSdxh7Cc--J6fExGb2ul48QTvN-KgGitEGgZw/edit?usp=drivesdk",
          "cachedResultName": "Facebook comments"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "740413cf-3dbb-4359-99f5-af9638ae770b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1360,
        -752
      ],
      "parameters": {
        "width": 784,
        "height": 768,
        "content": "## Extract & Analyze All Facebook Post Comments with Sentiment AI\n\nThis workflow automates the process of collecting, analyzing, and storing **Facebook post comments** with AI-powered **sentiment analysis* about YOUR Facebook Page.\n\n#### Typical Use Cases:\n\n* Social media sentiment monitoring\n* Brand reputation analysis\n* Campaign performance evaluation\n* Community management and moderation insights\n* Reporting and analytics for marketing teams\n\n### **How it works**\n\nThis workflow automates the end-to-end processing of Facebook post comments by fetching, analyzing, and storing them with AI-powered sentiment classification. It supports two execution modes: manual and triggered. In manual mode, a Manual Trigger starts the workflow using a Facebook Post ID, retrieves post details and all associated comments with pagination, and then delegates batch processing to a reusable sub-workflow. In triggered mode, it receives comment data from another workflow, splits it into batches, and processes each comment through Google Gemini for sentiment analysis. Results are written to Google Sheets using append-or-update logic to prevent duplicates and allow sentiment refreshes. Built-in batching, pagination handling, and wait nodes ensure scalability and API safety.\n\n### **Setup steps**\n\nFirst, configure Facebook Graph API credentials in the nodes responsible for fetching post details and comments. Next, set up valid Google Gemini (PaLM/Gemini) API credentials in the sentiment analysis node. Prepare a Google Sheet accessible via Google Sheets OAuth2 credentials, ensuring columns for POST ID, COMMENT ID, COMMENT, and SENTIMENT exist or can be auto-created. Verify that the \u201cCall \u2018Facebook\u2019\u201d node references an existing sub-workflow capable of processing comment batches. Optionally, adjust batch sizes in the loop node and delay settings in the wait node to handle rate limits. Finally, activate the workflow and test it using the Manual Trigger with a sample Facebook Post ID.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2df36b5f-e1fe-468f-a465-08765174eff7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -848,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 272,
        "content": "## STEP 4 -  Calculate sentiment\nClone [this Google Sheet](https://docs.google.com/spreadsheets/d/1xMLAtBgSdxh7Cc--J6fExGb2ul48QTvN-KgGitEGgZw/edit?usp=sharing) and set the POST ID as in the \"Set Fb post ID \" node.  Processes each comment through the sentiment analysis model (Google Gemini)"
      },
      "typeVersion": 1
    },
    {
      "id": "c636086e-4ef8-4097-a50a-5afc4321e8c5",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1360,
        48
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 272,
        "content": "## STEP 1 - Set Facebook Post\nSet your Facebook post ID  to analyze and add your Facebook Graph API credentials to both \"Get Fb Post\" and \"Get Fb comments\" nodes."
      },
      "typeVersion": 1
    },
    {
      "id": "5f570824-6097-47e7-a873-e213426ba411",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        48
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 272,
        "content": "## STEP 2 - Pagination\nIt's very IMPORTANT to get ALL comments"
      },
      "typeVersion": 1
    },
    {
      "id": "bc904013-1b1d-417d-bf87-90148096d809",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1312,
        512
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 256,
        "content": "## STEP 3 -  Get single comment\nProcess each comment batch"
      },
      "typeVersion": 1
    },
    {
      "id": "6c4ca593-ee60-471b-a86c-31323042e284",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2128,
        -720
      ],
      "parameters": {
        "color": 7,
        "width": 736,
        "height": 736,
        "content": "## MY NEW YOUTUBE CHANNEL\n\ud83d\udc49 [Subscribe to my new **YouTube channel**](https://youtube.com/@n3witalia). Here I\u2019ll share videos and Shorts with practical tutorials and **FREE templates for n8n**.\n\n[![image](https://n3wstorage.b-cdn.net/n3witalia/youtube-n8n-cover.jpg)](https://youtube.com/@n3witalia)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "08c98dbf-604c-43ec-bcd1-4325f2753319",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Next page?": {
      "main": [
        [
          {
            "node": "Get next comments page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add comment": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Fb Post": {
      "main": [
        [
          {
            "node": "Get Fb comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Fb post ID": {
      "main": [
        [
          {
            "node": "Get Fb Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Fb comments": {
      "main": [
        [
          {
            "node": "Call 'Facebook'",
            "type": "main",
            "index": 0
          },
          {
            "node": "Next page?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Sentiment Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sentiment Analysis": {
      "main": [
        [
          {
            "node": "Add comment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add comment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get next comments page": {
      "main": [
        [
          {
            "node": "Get Fb comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Sentiment Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Set Fb post ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}