Project

fb_scrape

0.0
No commit activity in last 3 years
No release in over 3 years
A gem to scrape facebook posts and comments
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 0
 Project Readme

FB_Scrape

This gem provides a utility for scraping facebook posts and comments. You will require a facebook app id to use this gem

Installation

Add this line to your application's Gemfile:

  gem 'fb_scrape'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install fb_scrape

Usage

Getting information about a Facebook page

  require 'fb_scrape'

  client = FBScrape::Client.new("page_name", "access_token")
  puts client.id
  puts client.name

Loading all the posts for an Facebook account

  require 'fb_scrape'
  client = FBScrape::Client.new("page_name", "access_token", "page_id")
  client.load

  puts client.posts.length

Limiting the number of posts

You can limit the number of posts returned

require 'fb_scrape'
client = FBScrape::Client.new("page_name", "access_token", "page_id", 10)
client.load

puts client.posts.length <= 10

Loading a post

  require 'fb_scrape'

  post = FBScrape::Post.load_from_id(id, access_token)    
  puts post.has_more_comments?

  post.load_all_comments
  puts post.has_more_comments?

Loading a comment and its replies

  require 'fb_scrape'

  comment = FBScrape::Comment.new(payload, access_token, page_id)
  comment.load_replies

  puts comment.comments.count
  puts comment.has_more_replies?
  comment.load_all_replies
  puts comment.comments.count

Loading an entire conversation

  require 'fb_scrape'

  conversation = FBScrape::Conversation.new(conversation_id, page_id, token)
  puts conversation.messages.count

Using the CLI

You can use the CLI to get a dump in JSON of posts and comments

  gem install fb_scrape

  fb_scrape help

  # get the page id for a url
  fb_scrape id --page_name theusername --token token

  # load all the posts for an account
  fb_scrape posts --page_name theusername --token token

  # load all the comments for a post
  fb_scrape comments --id post_id --token token --page_id page_id

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ongair/ig_scrape.

License

The gem is available as open source under the terms of the MIT License.