# 生成大量邀请令牌

**URL:** https://meta.discourse.org/t/generating-lots-of-invite-tokens/17563
**Category:** Plugin
**Tags:** deprecated, invites
**Created:** [2014年七月14日 16:35 UTC](https://meta.discourse.org/t/generating-lots-of-invite-tokens/17563 "2014-07-14T16:35:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2014年七月14日 16:35 UTC](https://meta.discourse.org/t/generating-lots-of-invite-tokens/17563/1 "2014-07-14T16:35:16Z")

</div>

> ⚠ **This plugin is deprecated** in favour of our core invite system.

**Summary** : Generate multiple invite tokens

🔗 **GitHub** : [https://github.com/discourse/discourse-invite-tokens](https://github.com/discourse/discourse-invite-tokens)  
➡ **Install** : Follow the [plugin installation guide](https://meta.discourse.org/t/install-a-plugin/19157).

## Configuration

### Enable plugin

After installing plugin enable site setting `invite tokens enabled`.

### Clone Discourse API Gem

If you already have Git and Ruby installed on your system, you can install Discourse API by running following command from console:

```
git clone https://github.com/discourse/discourse_api.git ~/discourse_api

```

### Generate Master API Key

Generate Master API Key for your Discourse instance by visiting `/admin/api`, to interact with Discourse API.

### Generate multiple Invite Tokens

Now that you have cloned Discourse API gem and generated master API key, let’s start generating invite tokens!

Open the `discourse_api/examples/disposable_invite_tokens.rb` file, and modify following information:

- Provide API credentials:

```plaintext
client = DiscourseApi::Client.new("http://localhost:3000")
client.api_key = "YOUR_API_KEY"
client.api_username = "YOUR_USERNAME"

```

Replace `http://localhost:3000` with the url of your discourse instance, eg: `http://discourse.example.com`

Replace `YOUR_API_KEY` with the master API key of your discourse instance, eg: `b1f3175cb682b3e9b6ca419db77772120b19af993cbc14ebed80fea08e3bbd66`

Replace `YOUR_USERNAME` with the Admin username of your discourse instance, eg: `codinghorror`

- Provide Invite Token details:

```plaintext
invite_tokens = client.disposable_tokens(username: "eviltrout", quantity: 200 , group_names: "security,support")

```

Replace `eviltrout` with the username of person whose account you want to be attached with generated invites.

Replace `200` with the quantity of tokens you want to generate.

The `group_names` parameter is optional. If you want invited users to be automatically added to specific group(s), specify the group names separated with comma. eg: `security,support`

Now in console, from `discourse_api` directory run:

```
ruby examples/disposable_invite_tokens.rb

```

This command will generate a `invite_tokens.csv` file inside `discourse_api/examples/` folder.

Open the `invite_tokens.csv` file and _voilà_ it will have 100 invite tokens ready to be used instantly!

## Prepare Invitation Links from Invite Token

The Invitation URL will be like:

```plaintext
http://discourse.example.com/invite-token/redeem/TOKEN?username=USERNAME&email=EMAIL&name=NAME&topic=TOPICID

```

Replace following fields:

- \*`discourse.example.com` with the URL of your Discourse instance.
- \*`TOKEN` with one of the 200 Invite tokens you just generated.
- \*`EMAIL` with the email of user you want to invite
- `USERNAME` with the desired username of invited user
- `NAME` with the first name of invited user
- `TOPIC` with the id of the topic to direct the user to after joining

(\*) these fields are required!

[Note that we use [Percent-encoding](http://en.wikipedia.org/wiki/Percent-encoding) in URL, so `space` needs to be specified as `%20`, `+` needs to be specified as `%2B`, etc.]

### Visit Invitation Link

When the user will visit Invitation Link, they will be registered, activated and logged in instantly. If you specified the groups while generating tokens, they will be automatically added to that group(s) when logged in.

That’s it! Start generating Invite Tokens for your Discourse instance today!

* * *

### **Update:** Now you can generate Invite links via UI!

To generate copyable invite link go to your invites page, click on “Send an Invite” button, enter the email of the user you want to invite, now click on “Copy Invite Link” button:

 ![](https://global.discourse-cdn.com/meta/original/3X/c/d/cd5ab6ecdbc5a91dc097fb4f5aae5d09941b3637.png) 

That’s it, now you will see copyable invite link:

 ![](https://global.discourse-cdn.com/meta/original/3X/7/d/7d1d54bae9e9c9b2cdc9714b3381603cc0ad352e.png) 

Copy and paste away! 🔗

### CHANGELOG

### TODO

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年六月18日 15:53 UTC](https://meta.discourse.org/t/generating-lots-of-invite-tokens/17563/45 "2024-06-18T15:53:25Z")

</div>


