• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

RedGlow/fbmastodon: Import script to mirror Facebook pages to Mastodon

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

RedGlow/fbmastodon

开源软件地址(OpenSource Url):

https://github.com/RedGlow/fbmastodon

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

FBMastodon

This tool is a simple NodeJS script that allows for (incremental) importing of posts in a Facebook page to a Mastodon profile.

The planned usage of this tool is to be setup with cron in order to periodically check for new posts and import them.

What do you need

In order to use this tool you need:

  • The Facebook page to mirror: you must be in control of an account which is administrator of the page (BEWARE: if this account gets blocked or removed, the mirroring will break, so choose a safe account)
  • A mastodon account to which to mirror
  • Node.js (this has been tested only on version 10.14.2)
  • A system which is permanently connected to internet and has a cron-like mechanism to periodically run tasks, or resort to run manually the task whenever you need to perform the synchronization
  • An average knowledge of how to get sources from Git, install software and write JSON files

Installation

Save the sources in the location where you want the script to run (I suggest to create a separate service account for that), and then run:

$ npm install

Running

In order to run the program you first have to prepare a configuration file (see below).

There is only one mandatory option, "--conf", to pass a configuration file containing all the data to perform the import. See below for the data needed and the structure of the configuration file.

To actually run the script:

$ node src/index.js --conf $CONF_FILE

Configuration

A configuration file contains various entries (each one represents the a page you want to mirror) and some settings which are shared by all the entries.

In order to add a new configuration entry, some data is needed:

  • Facebook: page id (the id of the page we want to import data from) and permanent auth token (used to run the APIs)
  • Mastodon auth token (used to post on Mastodon)

Below you get the instructions about how to obtain this data.

conf.json format

The conf.json is structured like this:

{
  "dbName": "posts.db",
  "entries": [
    {
      "name": "Robotizzato Amorepostaggio Pangalattico",
      "facebookAccessToken": "blabla",
      "pageId": "2162479640684043",
      "mastodonServerUrl": "https://mastodon.social",
      "mastodonAccessToken": "blabla"
    },
    {
      "name": "Mysterious Example Page",
      "facebookAccessToken": "blabla",
      "pageId": "49835938749205789",
      "mastodonServerUrl": "https://othermastodon.server",
      "mastodonAccessToken": "blabla"
    },
    ...
  ]
}

The configuration file has some key-values top level, and an entries key that contains an array of all the pages to mirror. Every top level key-value is mirrored into each entry automatically so, e.g., in the example above the "dbName" entry was copied into all the entries without the need to explicitly write it down.

The allowed keys for each entry are the following:

  • name (optional): the name of the page we are mirroring
  • facebookAccessToken: the Facebook permanent access token (see below)
  • pageId: the Facebook page id (see below)
  • mastodonServerUrl: the URL of the Mastodon server we want to mirror to
  • mastodonAccesstoken: the mastodon access token (see below)
  • dbLocation (optional): directory where to save the db of the mirror pages; if not given, it defaults to the program directory
  • dbName: the filename of the db; it will be joined with the dbLocation

How to obtain the Facebook data

Page ID

  • Go to the Facebook page you want to mirror
  • Left bar => About
  • At the end of the page you will find a "Page ID", something like "2162479640684043"

Facebook permanent auth token

This is the most tedious task, and it's better to split it into multiple steps, which are the creation of an app, the retrieval of a short lived auth token, then of a long lived auth token, and finally of the permanent auth token, which is what we need.

  • Creation of an App: this step creates an entity to which permissions are given and that will act on your behalf to access the facebook data
  • Get a short lived token
    • Go to https://developers.facebook.com/tools/explorer
    • Choose the Facebook App you just created
    • Choose "Get User Access Token" under "User or Page"
    • Confirm a user who is an admin of the page (REMEMBER: if this user gets suspended or deleted, the access to the page will break, so choose an FB account which will stay safe)
    • Add the permission "pages_show_list" (under the category "Events Groups Pages" of Add a Permission); adding this may ask you for which page you want the access of: confirm the page you're an admin for
    • Click "Get Access Token"
    • Copy the obtained access token
    • To test the procedure up to here: paste in the text input on top "pageid/feed?fields=id,message,attachments" (fill in the page id you obtained before) and click "Submit": if you obtain some JSON with data that contains presumably the latest post of your pages, you're ok to go
  • Get a long lived token
  • Get a permanent token
    {
      "name": "Mattia Belletti",
      "id": "10157428244468791"
    }
    
    {
      "data": [
          {
              "access_token": "EAAVSafgPW6wBAAct0P7_lots of characters_3hbwkJbIximtv9psxLJYmgZDZD",
              "category": "Health/Beauty",
              "category_list": [
                  {
                  "id": "2214",
                  "name": "Health/Beauty"
                  }
              ],
              "name": "Robotizzato Amorepostaggio Pangalattico",
              "id": "2162479640684043",
              "tasks": [
                  "ANALYZE",
                  "ADVERTISE",
                  "MODERATE",
                  "CREATE_CONTENT",
                  "MANAGE"
              ]
          }
      ],
      "paging": {
          "cursors": {
              "before": "MjE2MjQ3OTY0MDY4NDA0MwZDZD",
              "after": "MjE2MjQ3OTY0MDY4NDA0MwZDZD"
          }
      }
    }
    

How to obtain the Mastodon auth token

  • Go to your server's Mastodon home page.
  • Go to "Preferences" => Development
  • New Application
  • Set any application name and website, ignore the redirect URI, and set as Scopes only "read:statuses", "write:conversations", "write:media" and "write:statuses"
  • Enter the application you just created
  • Write down your access token: this is the mastodon auth token



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap