Skip to main content

A wrapper for the facebook-sdk which provides an ergonomic way to manage common interactions using the facebook-sdk

Project description

PyFB-kit

A Python wrapper for the Facebook Graph API that provides convenient abstractions for managing and moderating Facebook pages and comments.

Installation

Install the package using pip:

pip install pyfb-kit

Or using uv (recommended):

uv add pyfb-kit

Prerequisites

Before using this library, you need to obtain a long-lived user access token with the appropriate permissions:

  1. Create a Facebook developer application at developers.facebook.com/apps
  2. Add the following permissions to your application:
    • pages_manage_engagement
    • pages_read_engagement
    • pages_read_user_content
    • pages_show_list
  3. Generate a short-lived user access token via the Graph API Explorer with the above permissions
  4. Exchange it for a long-lived token (valid for up to 60 days) using the following request:
import requests

params = {
    "grant_type": "fb_exchange_token",
    "client_id": "<YOUR_APP_ID>",
    "fb_exchange_token": "<SHORT_LIVED_TOKEN>",
    "client_secret": "<YOUR_APP_SECRET>",
}

response = requests.get("https://graph.facebook.com/v24.0/oauth/access_token", params=params)
long_lived_token = response.json()["access_token"]

Usage

Basic Setup

from pyfb_kit import Client, Account, Post, Comment

# Initialize the client with your user access token
client = Client(user_access_token="your_long_lived_token_here")

Managing Accounts

Retrieve all Facebook pages associated with your account:

# Get all accessible accounts/pages
accounts = client.get_accounts()

# Print account information
for account in accounts:
    print(f"Page Name: {account.name}, ID: {account.id}")

Working with Posts

Fetch posts from a specific page:

# Get posts from a specific account
first_account = accounts[0]
posts = client.get_posts(first_account)

# Print post information
for post in posts:
    print(f"Post ID: {post.id}, Message: {post.message[:50]}...")

Comment Management

Interact with comments on posts:

# Get comments from a specific post
first_post = posts[0]
comments = client.get_comments(first_account, first_post)

# Print comment information
for comment in comments:
    print(f"Comment by {comment.from_info.name}: {comment.message[:50]}...")

# Post a new comment on a post
client.put_comment(first_account, first_post, "This is a new comment!")

# Reply to an existing comment
first_comment = comments[0]
client.reply_comment(first_account, first_comment, "Thanks for your comment!")

Advanced Comment Operations

Retrieve replies to a specific comment:

# Get all replies to a specific comment
replies = client.get_comment_replies(first_account, first_comment)

for reply in replies:
    print(f"Reply by {reply.from_info.name}: {reply.message[:50]}...")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfb_kit-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfb_kit-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file pyfb_kit-0.1.0.tar.gz.

File metadata

  • Download URL: pyfb_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyfb_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fccedd63bd03e37280fc35ce52b78fa1c18ecaa91cbcff38f18a11eba1da474c
MD5 d86ba6052286cf68e4772e49499986e4
BLAKE2b-256 5bcdf545fe32bb27d02ae4123e6602382883b2980e3c15ae0d0280ab0188a586

See more details on using hashes here.

File details

Details for the file pyfb_kit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyfb_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyfb_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf6b8765b351900796c9a42497bc580af7d476a4c4ba06699f4ff39e1a231eaf
MD5 662f5bb92d01e55d35817a442b329b6d
BLAKE2b-256 dbaf44a458a2497807e55719c6f3cbaefa344dce4d255ff00bfa07acb499efd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page