100 free credits. No credit card required. Get a key

How to scrape Facebook post with PHP

One public Facebook post by URL (post, video, reel, photo): message, author, published time, attachments, reaction, comment, share and view counts, and the top comments.

The examples use PHP’s curl extension and json_decode(..., true), so the response is a plain associative array. No Composer packages needed.

GET /v1/facebook/posts2 credits per callRefunded on failureBeta

Before you start

  1. Get an API keySign up for 100 free credits, no card. Keys start with gs_live_.
  2. Put it in the environmentEvery example reads it from GROUNDSOCIAL_API_KEY: export GROUNDSOCIAL_API_KEY=gs_live_…
  3. Set up PHPphp -m | grep curl # the curl extension ships with most PHP builds

Call Facebook post API from PHP

GET /v1/facebook/posts. Save this as main.php and run php main.php. It prints message and comment_count.

main.php
<?php

function groundsocial(string $path, array $params = []): array
{
    $url = 'https://api.groundsocial.dev' . $path . ($params ? '?' . http_build_query($params) : '');
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('GROUNDSOCIAL_API_KEY')],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 60,
    ]);
    $raw = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);
    $data = json_decode($raw, true);
    if ($status !== 200) {
        $e = $data['error'];
        throw new RuntimeException($e['code'] . ': ' . ($e['hint'] ?? $e['message']));
    }
    return $data;
}

$data = groundsocial('/v1/facebook/posts', ['url' => 'https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl']);

echo $data['message'], ' ', $data['comment_count'], PHP_EOL;

The response

A real Facebook response to this call, recorded from the live source and shortened for display: arrays keep their first items and … marks every cut. Live calls return current data in the same shape.

200 OK
{
  "post_id": "10118155444854771",
  "id": "UzpfSTQ6MTAxMTgxNTU0NDQ4NTQ3NzE6MTAxMTgxNTU0NDQ4NTQ3NzE=",
  "feedback_id": "ZmVlZGJhY2s6cGZiaWQwQ2o0N1Z5b3duUnl3amZZdXB5V2d5REtTbXYzYkZVRFJXTHB3akR6UFpkRjJtRmZSTVRXa3lNUzN2VlJvNXJleWw=",
  "url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl",
  "creation_time": 1793554070,
  "message": "Tried to get the family to dress as burger night, but couldn't corral the littlest burger",
  "author": {
    "id": "4",
    "name": "Mark Zuckerberg",
    "url": "https://www.facebook.com/zuck"
  },
  "attachments": [
    {
      "media": {
        "__typename": "Photo",
        "__isNode": "Photo",
        "id": "10118155440653191"
      },
      "styles": {
        "__typename": "StoryAttachmentAlbumStyleRenderer",
        "__isStoryAttachmentStyleRendererUnion": "StoryAttachmentAlbumStyleRenderer",
        "is_prod_eligible": true,
        "attachment": {
          "mediaset_token": "pcb.10118155444854771",
          "url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl",
          "all_subattachments": {
            "count": 3,
            "nodes": [
              "…"
            ]
          },
          "comet_product_tag_feed_overlay_renderer": null
        },
        "__module_operation_CometFeedStoryAttachmentMatchRenderer_attachment": {
          "__dr": "CometFeedStoryAlbumAttachmentStyle_styleTypeRenderer$normalization.graphql"
        },
        "__module_component_CometFeedStoryAttachmentMatchRenderer_attachment": {
          "__dr": "CometFeedStoryAlbumAttachmentStyle.react"
        }
      }
    }
  ],
  "reaction_count": 228529,
  "comment_count": 28701,
  "share_count": 6825,
  "video_view_count": null,
  "top_comments": [
    {
      "id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMTk4OTc5MTI5NTMwNzE0",
      "text": "What does a human burger taste like? 😉",
      "created_time": 1793558085,
      "author": {
        "id": "pfbid021StH2n3mR7TLVbLXnWPjqVdsugKkZsoiqacTjoP7PmA5oafkXG2BPXBHyTgfGsZsl",
        "name": "Hassan Hafez",
        "url": null
      }
    },
    {
      "id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMDU4MTYwMTkwNTk0NTEy",
      "text": "You all could have done the characters from Burger Time 😄",
      "created_time": 1793560720,
      "author": {
        "id": "pfbid02iz4RhdW3FTRS4LgtRhPWYWpXqYx1dEuVKVc7AvVMtxSMyrDhgoNfbig8UqMLU4J8l",
        "name": "Teri Mut",
        "url": null
      }
    },
    "… 8 more"
  ]
}

Top-level fields

FieldTypeDescription
post_idstring–
idstring | nullFacebook’s opaque node id for the story.
feedback_idstring | nullPass to facebook_post_comments to page through every comment.
urlstring–
creation_timeinteger | nullPublished, Unix seconds (UTC).
messagestring | null–
authorobject | null–
attachmentsobject[]Facebook’s attachments: photos, the video (with media.id), links.
reaction_countinteger | null–
comment_countinteger | null–
share_countinteger | null–
video_view_countinteger | null–
top_commentsobject[]The few top comments a logged-out visitor sees.

Parameters

NameInTypeDescription
url (required)querystringThe post URL. Example: https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl.

Errors and retries

Every error is JSON with error.code (stable: branch on it), message, hint (what to do next), docs_url and retryable. A failed call is never charged. Retry only when retryable is true, after the Retry-After header.

Errors
try {
    $data = groundsocial('/v1/facebook/posts', ['url' => 'https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl']);
} catch (RuntimeException $e) {
    // "code: hint", e.g. "target_not_found: ..." (never charged).
    fwrite(STDERR, $e->getMessage() . PHP_EOL);
    exit(1);
}
StatusMeaning
200The post.
400Invalid input. Nothing was charged.
401Missing or invalid API key.
402Not enough credits, a spend cap was reached, or payment is required.
403The target is private, or the account is suspended.
404The ad, Page or advertiser is not in the Meta Ad Library.
429Too many requests. Wait for Retry-After seconds.
503Facebook is temporarily unavailable. Retryable; nothing was charged.

Every error code and what to do about it.

Pricing

Cost
Per call2 credits per call
1,000 calls$2.00 on the starter pack, $0.80 at volume
No key (MPP or x402)$0.02 per call
Failed callRefunded, never charged

Every response has x-credits-charged and x-credits-remaining headers. Credits never expire. Packs and calculator.

From an AI agent (MCP)

The same call is the facebook_post_get tool on the hosted MCP server, so Claude, Cursor or any MCP client can make it without code. Add the server once:

bash
claude mcp add --transport http groundsocial https://api.groundsocial.dev/mcp

Then ask for it in words (“A public Facebook post: message, author, attachments, reactions, comments, shares, views, top comments”), or call the tool directly:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "facebook_post_get",
    "arguments": {
      "url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl"
    }
  }
}

MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.

Measure a post

Store reaction_count, comment_count, share_count and video_view_count hourly to chart how a post performs.

Keep going

Run it on your own data

One key for Facebook and 76 more platforms, over REST or MCP. Free credits on signup, no card.

Facebook is a trademark of Meta Platforms, Inc. We are not affiliated with or endorsed by Meta.