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

matoken/mastodon

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

开源软件名称(OpenSource Name):

matoken/mastodon

开源软件地址(OpenSource Url):

https://github.com/matoken/mastodon

开源编程语言(OpenSource Language):

Perl 100.0%

开源软件介绍(OpenSource Introduction):

Mastodon memo

Timelinesを眺める

home, public, tag/:hashtag, local なんかがある. アクセストークンがなくてもアクセス可能なのでアカウントを持っていないインスタンスも覗ける.

$ curl -sS 'https://mstdn.jp/api/v1/timelines/public' | jq -r ".[] | .account.display_name,.account.acct,.content" | lynx -stdin

検索してみる

日本語そのままは受け付けない

$ curl -sS 'https://inari.opencocon.org/api/v1/search?q=#東海道らぐ'
{"accounts":[],"statuses":[],"hashtags":[]}

URL encodeしたら受け付ける

$ echo '#東海道らぐ' | nkf -MQ | tr = %
%23%E6%9D%B1%E6%B5%B7%E9%81%93%E3%82%89%E3%81%90
$ curl -sS 'https://inari.opencocon.org/api/v1/search?q=%23%E6%9D%B1%E6%B5%B7%E9%81%93%E3%82%89%E3%81%90
{"accounts":[],"statuses":[],"hashtags":["東海道らぐ"]}

アクセストークンの取得

$ curl -X POST -sS https://inari.opencocon.org/api/v1/apps -F "client_name=PerlBot" -F "redirect_uris=urn:ietf:wg:oauth:2.0:oob" -F "scopes=read write follow" | jq .
{
  "id": 7,
  "redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
  "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
$ curl -X POST -sS https://inari.opencocon.org/oauth/token -d "client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=password&[email protected]&password=${MASTODONPASSWORD}&scope=read%20write%20follow" | jq .
{
  "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "token_type": "bearer",
  "scope": "read write follow",
  "created_at": 1492338622
}

※この方法では二段階認証が有効だと失敗する.一旦二段階認証を無効にしてアクセストークンを取得,その後二段階認証有効にしてもアクセストークンは利用できた.

follow list取得

Getting who account is following: GET /api/v1/accounts/:id/following

crontabで一日一回書き出す例. 自分のインスタンス分はインスタンス名がつかないのでawkで整形している.

8 3 * * *       curl -X GET -sS https://inari.opencocon.org/api/v1/accounts/3/following -d "client_id=&client_secret=&access_token=${TOKEN}" | jq -r .[].acct | awk '!match($0, /@/){print $0"@inari.opencocon.org"} match($0,/@/){print $0}' > ~/ownCloud/Documents/mastodon/[email protected]

ストリーミングAPI

とりあえず閲覧は出来るが流れが遅いとバッファーに溜まって遅延する. xxxx部分はaccess_token

$ curl --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -s https://inari.opencocon.org/api/v1/streaming/public | grep ^data: | sed -e 's/^.*: //' | jq -r .account.display_name,.account.acct,.content | xargs -n1 echo | lynx -stdin -dump

Perl module

$ cpanm Mastodon

Perlで文字投稿

  • toot.pl

ストリーミングをgolでpopup表示

参考URL




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
nothingface4u/mastodon · GitHub发布时间:2022-08-18
下一篇:
MrFDA/Mastodon: miscellanous scripts for Mastodon发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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