# Get Twitter Cookies

Get Twitter (X) session cookies in the cloud from one account login or your browser cookies, ready for Octoparse's Twitter Follower & Following Scraper.

- Template page: [https://www.octoparse.com/template/get-twitter-cookies](https://www.octoparse.com/template/get-twitter-cookies)
- Categories: Social Media
- Status: `PUBLISHED`
- Run mode: `CLOUD`

## Pricing

Free.

## What is an Octoparse template?

An Octoparse template is a ready-to-use scraping workflow with predefined inputs and structured outputs. Use the exact parameter keys below; do not invent parameters.

## Overview

This ready-to-use template collects structured data from general web pages.

## Output

The current workflow extracts 1 fields, including `cookies`.

## Use Cases

- Use structured results for research, comparison, and monitoring.
- Collect rows without building the extraction workflow from scratch.
- Combine results with other templates for downstream enrichment.
- Review a representative result before starting a large batch.

## Why Octoparse

- **No coding required:** complete Username (e.g. @elonmusk ), Password, Cookies from Browser (optional, check note 3 on Information) and start the template in cloud mode.
- **Flexible export:** review and export results as CSV, Excel, or JSON.

## Input

### Username (e.g. @elonmusk )

Required. 推特用户名，如@cE123123（注意不是邮箱，是用户名，因为如果输入的是邮箱，还会被要求输入用户名进行验证） Constraints: minItems=1; maxItems=100; items.minLength=1; items.maxLength=111111.

### Password

Required. Password Constraints: minLength=1; maxLength=10000.

### Cookies from Browser (optional, check note 3 on Information)

Optional. 如果某些用户账号被封控，可以手动复制登录后的cookies，进行格式转换 Constraints: minLength=1; maxLength=10000.

## How to Use

# Get Twitter Cookies

Get Twitter Cookies is an Octoparse template that signs in to X (Twitter) in Octoparse Cloud or converts browser cookies into session cookies. Use it to prepare a logged-in X session for templates that require one, such as [Twitter Follower & Following Scraper](https://www.octoparse.com/template/twitter-follower-list-scraper). Sign-in runs in the cloud; no local browser needs to stay open.

Data source: [X (Twitter)](https://x.com/).

## Pricing and access

- Free; no per-line usage fee.
- Requires Octoparse Standard plan or higher; plan resource limits apply.
- See [Octoparse pricing](https://www.octoparse.com/pricing).

## Output

- `cookies`: X session cookies in the format accepted by Twitter Follower & Following Scraper’s **Twitter Cookies** field.
- `html`: screenshot of the X page reached during sign-in, as an encoded image string. Use it to check whether X requested extra verification.
- `error`: explains why a pasted cookie string was rejected, e.g. missing `auth_token`.

## Inputs

- **Username (e.g. @elonmusk)** (Required): one X username in `@username` format, not an email address. Email sign-in can trigger an extra username check. One account per run.
- **Password** (Required): password for that X account. Used only to sign in to X during this run; it is not written to output data. For extra safety, use a dedicated X account instead of your main one.
- **Cookies from Browser** (Optional): cookie string copied from a browser already logged in to X. It must include an `auth_token` value. Use when X blocks or challenges password sign-in.

## How to use

1. [Create a free Octoparse account](https://www.octoparse.com/console/trial).
2. Open [Get Twitter Cookies](https://www.octoparse.com/console/template/get-twitter-cookies) and select **Try it!**.
3. Enter one X username and password, or paste a cookie string into **Cookies from Browser**.
4. Start the task in Octoparse Cloud.
5. Copy the `cookies` value from results and paste it into the **Twitter Cookies** field of Twitter Follower & Following Scraper.

## Get browser cookies

Log in to x.com in Chrome or Edge. Press F12, open the **Network** tab, refresh the page, select a request sent to x.com, and copy the full value of the `Cookie` request header. Paste it into **Cookies from Browser**; ensure it contains `auth_token`.

## Limitations

- One X account per run.
- Accounts that X asks to confirm with a phone number or email during sign-in will not complete through password sign-in. The template does not retry or switch accounts automatically.
- A **Cookies from Browser** string without a valid `auth_token` value is rejected and reported in `error`.
- X cookies stop working when X ends the session, e.g. after logout or password change.

## Tips

- Linked workflow: run Get Twitter Cookies, copy `cookies`, paste into **Twitter Cookies** of Twitter Follower & Following Scraper, then add up to 5,000 X account URLs whose followers or followings you want.
- Stay logged in to X in the browser used for cookie copying. Logging out ends the session and the cookies stop working downstream.
- If Twitter Follower & Following Scraper reports an invalid or expired session, run Get Twitter Cookies again and replace the old value.
- Use `@username`, not email, to avoid X’s extra username check for email sign-ins.
- Anyone with your session cookies can act as your account. Keep exported cookies private.
- Password sign-in returns an `html` screenshot; to get reusable cookies immediately, use **Cookies from Browser** with an already logged-in cookie string.

## Automation

After the session works, schedule the downstream follower task or run it through [Octoparse API](https://www.octoparse.com/open-api) or [Octoparse MCP server](https://www.octoparse.com/mcp).

## Limitations

Results depend on what the source site exposes at run time. Fields may be empty when a source page does not provide a value. The template enforces the input limits shown above.

## Tips

Use specific, valid inputs and review a representative result before starting a large batch. Remove duplicate inputs when repeated records are not needed.

## FAQ

### What do I need to enter?

Use the exact inputs and limits listed above.

### What data does this template return?

See Output Schema below; availability can vary by source record.

### How is usage billed?

See the Pricing section above for current pricing and billing details.

## Related Templates

- [Twitter Advanced Search Scraper](https://www.octoparse.com/template/twitter-scraper-by-keywords)
- [Twitter Scraper (by Account URL)](https://www.octoparse.com/template/twitter-scraper-by-account-url)
- [Twitter Scraper (by hashtag)](https://www.octoparse.com/template/twitter-scraper-by-hashtag)
- [Twitter (X) Comments Scraper](https://www.octoparse.com/template/tweets-comments-scraper-by-search-result-url)

## Input Schema

```json
{
  "title": "Get Twitter Cookies input",
  "description": "Input parameters configured for the current published template version.",
  "type": "object",
  "schemaVersion": 1,
  "additionalProperties": false,
  "properties": {
    "username": {
      "title": "Username (e.g. @elonmusk )",
      "description": "推特用户名，如@cE123123（注意不是邮箱，是用户名，因为如果输入的是邮箱，还会被要求输入用户名进行验证）",
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 111111
      },
      "minItems": 1,
      "maxItems": 100,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "password": {
      "title": "Password",
      "description": "Password",
      "type": "string",
      "minLength": 1,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "cookies_from_Browser": {
      "title": "Cookies from Browser (optional, check note 3 on Information)",
      "description": "如果某些用户账号被封控，可以手动复制登录后的cookies，进行格式转换",
      "type": "string",
      "minLength": 1,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    }
  },
  "required": [
    "username",
    "password"
  ]
}
```

## Input JSON Example

Example 1

```json
{
  "cookies_from_Browser": "night_mode=2; g_state={\"i_l\":0}; kdt=ZUEeEx86FZJZsevw5nurf9G4OjUK5RVY4BXm8hnP; dnt=1; des_opt_in=Y; _ga=GA1.2.568689135.1729744830; guest_id=v1%3A172981879665407960; guest_id_marketing=v1%3A172981879665407960; guest_id_ads=v1%3A172981879665407960; auth_token=6316dd0b94a3893cf0886522f4f1b36ccbf9ddf3; ct0=158ee749f7b565d1bef1ac962edb9708eea2beefa5888e3d94381011583125ad71ce21463fb0878904b9236104eeff65c4f7cf3d04fe1e845a5bed25d28e7d2bc1726bce585e968dda53924247ebff2c; twid=u%3D499321085; att=1-nUESPh8KRxQeuhYaArT8i1zJIa1YfjKyRFrAGvSE; personalization_id=\"v1_6VBscQVGqR/2LBi7I6amOg==\"; lang=en",
  "password": "Lolabulldewg99!!",
  "username": [
    "@davelemon"
  ]
}
```

Example 2

```json
{
  "cookies_from_Browser": "lang=en; d_prefs=MToxLGNvbnNlbnRfdmVyc2lvbjoyLHRleHRfdmVyc2lvbjoxMDAw; guest_id_ads=v1%3A163969092460350613; guest_id_marketing=v1%3A163969092460350613; _ga=GA1.2.1201487867.1682506322; _gid=GA1.2.1554300394.1692015898; g_state={\"i_l\":0}; personalization_id=\"v1_csLRi+jTzepx7xZQQgNsug==\"; guest_id=v1%3A169201722169344595; _twitter_sess=BAh7CSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCHfjFfSJAToMY3NyZl9p%250AZCIlYjU1NzgzOGUyYWI4ZThiODcwODUzYTRkZmYyMjEyOTI6B2lkIiUxOTRi%250AODAyMzYxZDNlZWEyNDIwM2VjODMwNTk3MDA4Ng%253D%253D--0c84c741ee793fbfb5e58f688c0be8b16841c832; kdt=r2NfR5TSDAe2pxA6PLtvwJveTcWSSFlEfrfgqBZ8; auth_token=9963385e5f38f55a6d4a2bd1ff8cfcbee1712f39; ct0=9b773852f8ef47e014602e277b1f72cce19f4015e4609e16ae24c07141f737a45bd03d5b5aeb7b11335ea3c53ce5789b2382a42edf9ab2d25f6eb0339ead9e64a6a424508f825284a02179596d27ea1a; att=1-ByHk2tgN6QSJvOceYRi4n1d8Y9yiBcmrqwf7BPQh; twid=u%3D1224619645732147202",
  "password": "xsw888888",
  "username": [
    "@Alanwind6"
  ]
}
```


## Output Schema

```json
{
  "schemaVersion": 1,
  "type": "object",
  "properties": {
    "cookies": {
      "type": "string",
      "description": ""
    }
  },
  "title": "Get Twitter Cookies output",
  "description": "Initial output fields derived from the current published implementation. Field descriptions are maintained by Data Center; production field names and types should be refreshed from recent successful runs.",
  "additionalProperties": false
}
```

## Output Example

Example 1

```json
{
  "cookies": "[{'name': 'night_mode', 'value': '2'}, {'name': 'g_state', 'value': '{\"i_l\":0}'}, {'name': 'kdt', 'value': 'ZUEeEx86FZJZsevw5nurf9G4OjUK5RVY4BXm8hnP'}, {'name': 'dnt', 'value': '1'}, {'name': 'des_opt_in', 'value': 'Y'}, {'name': '_ga', 'value': 'GA1.2.568689135.1729744830'}, {'name': 'guest_id', 'value': 'v1%3A172981879665407960'}, {'name': 'guest_id_marketing', 'value': 'v1%3A172981879665407960'}, {'name': 'guest_id_ads', 'value': 'v1%3A172981879665407960'}, {'name': 'auth_token', 'value': '6316dd0b94a3893cf0886522f4f1b36ccbf9ddf3'}, {'name': 'ct0', 'value': '158ee749f7b565d1bef1ac962edb9708eea2beefa5888e3d94381011583125ad71ce21463fb0878904b9236104eeff65c4f7cf3d04fe1e845a5bed25d28e7d2bc1726bce585e968dda53924247ebff2c'}, {'name': 'twid', 'value': 'u%3D499321085'}, {'name': 'att', 'value': '1-nUESPh8KRxQeuhYaArT8i1zJIa1YfjKyRFrAGvSE'}, {'name': 'personalization_id', 'value': '\"v1_6VBscQVGqR/2LBi7I6amOg==\"'}, {'name': 'lang', 'value': 'en'}]"
}
```

Example 2

```json
{
  "cookies": "[{'name': 'lang', 'value': 'en'}, {'name': 'd_prefs', 'value': 'MToxLGNvbnNlbnRfdmVyc2lvbjoyLHRleHRfdmVyc2lvbjoxMDAw'}, {'name': 'guest_id_ads', 'value': 'v1%3A163969092460350613'}, {'name': 'guest_id_marketing', 'value': 'v1%3A163969092460350613'}, {'name': '_ga', 'value': 'GA1.2.1201487867.1682506322'}, {'name': '_gid', 'value': 'GA1.2.1554300394.1692015898'}, {'name': 'g_state', 'value': '{\"i_l\":0}'}, {'name': 'personalization_id', 'value': '\"v1_csLRi+jTzepx7xZQQgNsug==\"'}, {'name': 'guest_id', 'value': 'v1%3A169201722169344595'}, {'name': '_twitter_sess', 'value': 'BAh7CSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCHfjFfSJAToMY3NyZl9p%250AZCIlYjU1NzgzOGUyYWI4ZThiODcwODUzYTRkZmYyMjEyOTI6B2lkIiUxOTRi%250AODAyMzYxZDNlZWEyNDIwM2VjODMwNTk3MDA4Ng%253D%253D--0c84c741ee793fbfb5e58f688c0be8b16841c832'}, {'name': 'kdt', 'value': 'r2NfR5TSDAe2pxA6PLtvwJveTcWSSFlEfrfgqBZ8'}, {'name': 'auth_token', 'value': '9963385e5f38f55a6d4a2bd1ff8cfcbee1712f39'}, {'name': 'ct0', 'value': '9b773852f8ef47e014602e277b1f72cce19f4015e4609e16ae24c07141f737a45bd03d5b5aeb7b11335ea3c53ce5789b2382a42edf9ab2d25f6eb0339ead9e64a6a424508f825284a02179596d27ea1a'}, {'name': 'att', 'value': '1-ByHk2tgN6QSJvOceYRi4n1d8Y9yiBcmrqwf7BPQh'}, {'name': 'twid', 'value': 'u%3D1224619645732147202'}]"
}
```

## API

`POST https://openapi.octoparse.com/api/agentTools/executeTask`

This is the OpenAPI Agent Tools `executeTask` endpoint. Authenticate with a Bearer token.

Request body:

`templateName` is the template slug; `parameters` is a JSON object string whose keys match Input Schema; `taskName`, `idempotencyKey`, and `maxCollectedRows` are optional.

Obtain a token:

```http
POST https://openapi.octoparse.com/token
Content-Type: application/json

{
  "username": "YOUR_USERNAME",
  "password": "YOUR_PASSWORD",
  "grant_type": "password"
}
```

Use `data.access_token` as `Authorization: Bearer <token>`. After starting, poll `getTaskStatus` and export with `exportData`.

```json
{
  "templateName": "get-twitter-cookies",
  "taskName": "Get Twitter Cookies",
  "parameters": "{\"cookies_from_Browser\":\"night_mode=2; g_state={\\\"i_l\\\":0}; kdt=ZUEeEx86FZJZsevw5nurf9G4OjUK5RVY4BXm8hnP; dnt=1; des_opt_in=Y; _ga=GA1.2.568689135.1729744830; guest_id=v1%3A172981879665407960; guest_id_marketing=v1%3A172981879665407960; guest_id_ads=v1%3A172981879665407960; auth_token=6316dd0b94a3893cf0886522f4f1b36ccbf9ddf3; ct0=158ee749f7b565d1bef1ac962edb9708eea2beefa5888e3d94381011583125ad71ce21463fb0878904b9236104eeff65c4f7cf3d04fe1e845a5bed25d28e7d2bc1726bce585e968dda53924247ebff2c; twid=u%3D499321085; att=1-nUESPh8KRxQeuhYaArT8i1zJIa1YfjKyRFrAGvSE; personalization_id=\\\"v1_6VBscQVGqR/2LBi7I6amOg==\\\"; lang=en\",\"password\":\"Lolabulldewg99!!\",\"username\":[\"@davelemon\"]}"
}
```

## Python Example

```python
import json
import requests

OPENAPI_BASE = "https://openapi.octoparse.com"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"

parameters = json.loads("{\"cookies_from_Browser\":\"night_mode=2; g_state={\\\"i_l\\\":0}; kdt=ZUEeEx86FZJZsevw5nurf9G4OjUK5RVY4BXm8hnP; dnt=1; des_opt_in=Y; _ga=GA1.2.568689135.1729744830; guest_id=v1%3A172981879665407960; guest_id_marketing=v1%3A172981879665407960; guest_id_ads=v1%3A172981879665407960; auth_token=6316dd0b94a3893cf0886522f4f1b36ccbf9ddf3; ct0=158ee749f7b565d1bef1ac962edb9708eea2beefa5888e3d94381011583125ad71ce21463fb0878904b9236104eeff65c4f7cf3d04fe1e845a5bed25d28e7d2bc1726bce585e968dda53924247ebff2c; twid=u%3D499321085; att=1-nUESPh8KRxQeuhYaArT8i1zJIa1YfjKyRFrAGvSE; personalization_id=\\\"v1_6VBscQVGqR/2LBi7I6amOg==\\\"; lang=en\",\"password\":\"Lolabulldewg99!!\",\"username\":[\"@davelemon\"]}")

response = requests.post(
    f"{OPENAPI_BASE}/api/agentTools/executeTask",
    headers={
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        "templateName": "get-twitter-cookies",
        "taskName": "Get Twitter Cookies",
        "parameters": json.dumps(parameters, ensure_ascii=False),
    },
    timeout=60,
)
print(response.status_code)
print(response.json())
```

## HTTP/cURL Example

```bash
curl -X POST "https://openapi.octoparse.com/api/agentTools/executeTask" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "templateName": "get-twitter-cookies",
  "taskName": "Get Twitter Cookies",
  "parameters": "{\"cookies_from_Browser\":\"night_mode=2; g_state={\\\"i_l\\\":0}; kdt=ZUEeEx86FZJZsevw5nurf9G4OjUK5RVY4BXm8hnP; dnt=1; des_opt_in=Y; _ga=GA1.2.568689135.1729744830; guest_id=v1%3A172981879665407960; guest_id_marketing=v1%3A172981879665407960; guest_id_ads=v1%3A172981879665407960; auth_token=6316dd0b94a3893cf0886522f4f1b36ccbf9ddf3; ct0=158ee749f7b565d1bef1ac962edb9708eea2beefa5888e3d94381011583125ad71ce21463fb0878904b9236104eeff65c4f7cf3d04fe1e845a5bed25d28e7d2bc1726bce585e968dda53924247ebff2c; twid=u%3D499321085; att=1-nUESPh8KRxQeuhYaArT8i1zJIa1YfjKyRFrAGvSE; personalization_id=\\\"v1_6VBscQVGqR/2LBi7I6amOg==\\\"; lang=en\",\"password\":\"Lolabulldewg99!!\",\"username\":[\"@davelemon\"]}"
}
JSON
```

## MCP Setup

Connect an MCP-compatible AI client to `https://mcp.octoparse.com` using browser OAuth or an Octoparse API key. Find `get-twitter-cookies`, inspect its inputs, create a cloud task with the exact Input Schema keys, and export JSON results.

## Machine-readable Resources

- [Template contract](https://www.octoparse.com/templates/get-twitter-cookies.json)
- [Manifest](https://www.octoparse.com/templates/get-twitter-cookies-manifest.json)
