Skip to content

Facebook graph API rest implementation in rust.

Notifications You must be signed in to change notification settings

tomc1998/rust-fbapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-fbapi

Facebook graph API rest implementation in rust.

Completeness

Not even close! This library is only currently used for personal use, and I'll add features to it as I need them.

Abusing Rust's type sytem

Currently graph edges are just 'stringly typed', so it's easy to get runtime errors by attempting to populate a struct which doesn't match the edge requested. In the future, this should be solved using enums for edge URIs, with a custom 'request by string' method for complex requests that aren't supported by the type system.

Running tests

To run the tests, a valid user access token is needed. This is currently hardcoded into the tests/mod.rs file, as a static variable called ACCESS_TOKEN.

Example

This example is taken from examples/get_user.rs. Here we read the access token from stdin, then use the access token to request the name and picture of the user. We then print the user's name to the console.

extern crate fbapi;

fn main() {
  use std::io;

  // Read access token from stdin
  println!("Input access token: ");
  let mut buffer = String::new();
  let stdin = io::stdin();
  stdin.read_line(&mut buffer).unwrap();

  let access_token = &buffer;


  println!("Making request to facebook api...");

  let fb_api = fbapi::FBApi::new((2, 9)); // Initialise api version 2.9

  // Setup edge, request picture, gender, first name and last name
  let mut user_edge = fbapi::graph::Edge::user_me();
  user_edge.add_fields(vec!["picture", "gender", "first_name", "last_name"]);

  // Actually make the request and deserialize into fbapi::model::User type
  let user : fbapi::model::User = fb_api.get(user_edge, access_token).unwrap();

  // Print the result
  println!("User name = {} {}", user.first_name.unwrap(), user.last_name.unwrap());
}

About

Facebook graph API rest implementation in rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages