Facebook 群组数据

Facebook group data

嗨,我正在关注这个:

How To Download Your Facebook Group Data

Here are instructions for Mac users to download Facebook group data, courtesy of Al Shaw.

  1. Get an access token for your group from the Facebook Graph API Explorer. A box will pop up. Make sure you click the user.groupspermission, and then click Get Access Token again. Copy and paste this into a text editor.
  2. Copy and paste your group ID (example: https://www.facebook.com/groups/209024949216061/) into a text editor. You can also test your group ID in the Facebook Graph API Explorer by entering “GROUPID/feed” in the get field. You should see all of your group posts.
  3. Grab the script for scraping the feed here: https://gist.github.com/4322279/
  4. Click “download gist” and decompress the file on your computer.
  5. Navigate to where that file exists in the terminal (example: iMac:/ myname$ cd /Users/myname/documents). Here are instructions on how to use the terminal. Stack Overflow is also a good place to go with questions.
  6. In your terminal, type: “sudo gem install crack fastercsv rest-client” and hit return. You’ll have to enter your network password.
  7. Type: “ruby fb_scrape.rb YOUR_ACCESS_TOKEN YOUR_GROUP_ID” and hit return. Make sure to note that this is two pieces of information: your access token, and your group id – both of which you pasted into a text editor earlier.

You'll see all the Facebook data fly across the screen. A file should show up in your gist folder (check in your Finder) called fb_posts_GROUPID.csv (with that long number being the group ID you put in). Click to open, and you have your spreadsheet!

如果我全部完成然后发出我得到的命令:

$ ruby fb_scrape.rb CAACEdEomyaccesstokenZD 2017mygroup6335
/var/lib/gems/1.9.1/gems/crack-0.4.2/lib/crack/json.rb:33:in `rescue in parse': Invalid JSON string (Crack::ParseError)
    from /var/lib/gems/1.9.1/gems/crack-0.4.2/lib/crack/json.rb:26:in `parse'
    from fb_scrape.rb:28:in `scrape'
    from fb_scrape.rb:24:in `start'
    from fb_scrape.rb:78:in `<main>'

我应该如何修复它以及为什么它不起作用? 谢谢!

我更改了几行,它正在使用 Ruby 2.3.1p112

  • 已添加

    需要'json'

    需要'csv'

  • 已更改(fastercsv -> csv & Crack::JSON.parse -> JSON.parse()

    resp = JSON.parse(RestClient.get(url))

    CSV.open("fb_posts_#{@group_id}.csv", "w") |csv|