6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TypeScriptでConnpassイベントの参加者を取得する

Last updated at Posted at 2019-08-27

本稿ではTypeScriptでConnpassイベントの参加者を取得する方法を説明する。

get-connpass-applicantsモジュールをインストールする

yarn add @suin/get-connpass-applicants

このモジュールは、ConnpassイベントのURLを渡すと、そのイベントの申込者情報を返してくれるもの。

実装

上記のモジュールを使って、任意のConnpassイベントの参加者を取得してみる。

main.ts
import { getConnpassApplicants, Applicants } from '@suin/get-connpass-applicants'

(async () => {
  const url = 'https://yyts.connpass.com/event/144568/'
  const applicants = await getConnpassApplicants(url)
  console.log(JSON.stringify(applicants, null, '  '))
})()

実行結果

{
  "participants": [
    {
      "url": "https://connpass.com/user/OkinaKahiro/",
      "name": "kahirokunn",
      "participationType": "現地参加"
    },
    {
      "url": "https://connpass.com/user/suin/",
      "name": "suin",
      "participationType": "主催者・スタッフ枠"
    },
    {
      "url": "https://connpass.com/user/picric/",
      "name": "kakiuchi",
      "participationType": "現地参加"
    },
    {
      "url": "https://connpass.com/user/zima_gen/",
      "name": "zima",
      "participationType": "現地参加"
    }
  ],
  "waitlist": [],
  "cancelled": []
}

participantsByParticipationTypeプロパティを参照すれば、申込み枠ごとにグルーピングした参加者リストも取得できる。戻り値はES6のMapで返ってくる。

console.log(applicants.participantsByParticipationType)

実行結果

Map {
  '現地参加' => [ Applicant {
      url: 'https://connpass.com/user/OkinaKahiro/',
      name: 'kahirokunn',
      participationType: '現地参加' },
    Applicant {
      url: 'https://connpass.com/user/picric/',
      name: 'kakiuchi',
      participationType: '現地参加' },
    Applicant {
      url: 'https://connpass.com/user/zima_gen/',
      name: 'zima',
      participationType: '現地参加' } ],
  '主催者・スタッフ枠' => [ Applicant {
      url: 'https://connpass.com/user/suin/',
      name: 'suin',
      participationType: '主催者・スタッフ枠' } ] }
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?