/automate-posting-app

This is a project that aims to automate posting on to the social media sites through a dedicated program.

Primary LanguagePythonMIT LicenseMIT

Automated Social Media Posting Program (Under-Work)

Overview

This program automates posting images, documents, and texts across Facebook, Instagram, and WhatsApp.

Installation

  1. Clone the repository.
  2. Install dependencies: pip install -r requirements.txt

Usage

  • Update config.py with your credentials.
  • Run main.py to start posting.

Facebook API Wrapper

This class provides methods to interact with the Facebook Graph API. You can use it to post text, images, and videos to Facebook pages or personal accounts, and to edit existing posts.

Requirements

  • requests library: Make sure to install it using pip install requests.
  • A valid Facebook access token with the required permissions.

Class: Facebook

Constructor

__init__(self, access_token: str)

Parameters:

  • access_token (str): Your Facebook Graph API access token.

Description:

Initializes the Facebook class and sets up the API client. Fetches the user's details and a list of pages that the user has access to.

Method: _requester

_requester(self, url: str, method: str = 'get', params: dict = {}, files: dict = {}, new_access_token: str = '')

Parameters:

  • url (str): The URL for the API request.
  • method (str): The HTTP method to use (get, post, delete). Default is get.
  • params (dict): Parameters to include in the request.
  • files (dict): Files to upload (e.g., images or videos).
  • new_access_token (str): A new access token to use for this request. If not provided, the class's default token is used.

Returns:

  • dict: The response from the API or an error message.

Description:

Handles API requests with error handling.

Method: post_text

post_text(self, page_id: str, message: str)

Parameters:

  • page_id (str): The page ID or 'me' for personal account.
  • message (str): The message content to post.

Returns:

  • dict: The API response, including the result of the post operation.

Description:

Posts text to a specified page or personal account. If page_id is 'me', it posts to the authenticated user's account.

Method: edit_post

edit_post(self, post_id: str, message: str)

Parameters:

  • post_id (str): The ID of the post to edit.
  • message (str): The new message content.

Returns:

  • dict: The API response, including the result of the edit operation.

Description:

Edits an existing post on a page or personal account.

Method: get_pages_list

get_pages_list(self) -> list

Returns:

  • list: A list of pages that the user has access to.

Description:

Fetches the list of pages that the authenticated user has access to.

Example Usage

# Instantiate the Facebook class with your access token
fba = Facebook('YOUR_ACCESS_TOKEN')

# Post text to a page or personal account
response = fba.post_text('PAGE_NAME', 'Hello, world!\nThis is an automated post generated by the python script.')
print(response)

# Edit a post
post_id = 'YOUR_POST_ID'
new_message = 'This is the updated content of the post.'
edit_response = fba.edit_post(post_id, new_message)
print(edit_response)

Notes

  • Ensure that your access token has the pages_manage_posts permission to edit posts on pages.
  • Verify that the post_id is correct and that the post belongs to the authenticated user or the page specified.

Troubleshooting

  • 403 Forbidden Error: This may occur if the access token does not have the required permissions or if the post ID is incorrect.
  • 401 Unauthorized Error: Check if your access token is valid and has not expired.

Contribution

Feel free to submit pull requests or open issues.

License

MIT License