#facebook #api-client #post #upload #api #video #page

fb_poster

An unofficial Rust API client for Facebook post uploads

7 releases

0.1.8 Apr 5, 2024
0.1.7 Mar 8, 2024
0.1.6 Feb 26, 2024

#437 in Web programming

Download history 7/week @ 2024-01-31 2/week @ 2024-02-14 163/week @ 2024-02-21 70/week @ 2024-02-28 114/week @ 2024-03-06 10/week @ 2024-03-13 2/week @ 2024-03-27 134/week @ 2024-04-03 8/week @ 2024-04-10

144 downloads per month

MIT license

18KB
366 lines

An unofficial Rust API client for Facebook post uploads.

🪛 Requirements

  • Create a Fecebook app on Developer Page

  • Your Facebook app must be in Live mode to make your posts visible for others.

  • Take ACCESS_TOKEN from Graph API Explorer. You can get 2 months token by pressing info icon.

  • Add the desired permissions to allow your app to make posts.

    • pages_manage_engagement
    • pages_manage_posts
    • pages_read_engagement
    • pages_read_user_engagement
    • publish_video permission, if you need to publish a video
  • Take PAGE_ID from page that you planning to do post.

  • More useful information you can find in Offical Facebook API Documentation Current version v19.0.

🪧 Usage

Post

use fb_poster::*;
use anyhow::{Ok, Result};

const ACCESS_TOKEN: &str = "YOUR_ACCESS_TOKEN";
const PAGE_ID: &str = "YOUR_PAGE_ID";


#[tokio::main]
async fn main() -> Result<()> {
    // Bring your secrets into a scope
    let secrets = Secrets::new(ACCESS_TOKEN, PAGE_ID);

    
    let message = "Your message".to_string();
    let link = "https://your_link".to_string();

    // Build a body for a request
    let body = Post::new(secrets)
    .with_message(message)
    .with_link(link);

    // Sending and get repsonse
    body.send().await?;

    Ok(())
}

Photo

use fb_poster::*;
use anyhow::{Ok, Result};

const ACCESS_TOKEN: &str = "YOUR_ACCESS_TOKEN";
const PAGE_ID: &str = "YOUR_PAGE_ID";


#[tokio::main]
async fn main() -> Result<()> {
    // Bring your secrets into a scope
    let secrets = Secrets::new(ACCESS_TOKEN, PAGE_ID);

    let path = "/path/to/photo.png".to_string();

    // Build a body for a request
    let body = Photo::new(secrets, path);

    // Sending and get repsonse
    body.send(&secrets).await?;

    Ok(())
}

Video

use fb_poster::*;
use anyhow::{Ok, Result};

const ACCESS_TOKEN: &str = "YOUR_ACCESS_TOKEN";
const PAGE_ID: &str = "YOUR_PAGE_ID";


#[tokio::main]
async fn main() -> Result<()> {
    // Bring your secrets into a scope
    let secrets = Secrets::new(ACCESS_TOKEN, PAGE_ID);


    let path = "/path/to/video".to_string(); // or url for .hosted_video()
    let title = "Title".to_string();
    let description = "Description".to_string();
    let thumb = "path/to/thumb".to_string();

    // Build a body for a request
    let body = Video::new(secrets)
    .local_video(path)
    .with_title(title)
    .with_description(description)
    .with_thumbnail(thumb)


    // Sending and get repsonse
    body.send().await?;

    Ok(())
}

Reels

use fb_poster::*;
use anyhow::{Ok, Result};

const ACCESS_TOKEN: &str = "YOUR_ACCESS_TOKEN";
const PAGE_ID: &str = "YOUR_PAGE_ID";


#[tokio::main]
async fn main() -> Result<()> {
    // Bring your secrets into a scope
    let secrets = Secrets::new(ACCESS_TOKEN, PAGE_ID);


    let path = "/path/to/video".to_string(); // or url for .hosted_video()
    let title = "Title".to_string();
    let description = "Description".to_string();
    let thumb = "path/to/thumb".to_string();

    // Build a body for a request
    let body = Reels::new(secrets)
    .local_video(path)
    .with_description(description)

    // Sending and get repsonse
    body.send().await?;

    Ok(())
}

✅ Features

  • Post
    • With Message
    • With Link
  • Photo
    • With Message

Non-Resumable Upload (Video limitation is 1GB 20min)

  • Video

    • Local Video
    • Hosted Video
    • With Title
    • With Description
    • With Thumbnail
  • Reels

    • Local Reels
    • Hosted Reels
    • With Description

Dependencies

~6–19MB
~266K SLoC