---
title: "启用或停用一个新闻来源"
canonical_url: "https://tweetstream.io/zh-cn/docs/api/set-news-source-enabled"
last_updated: 2026-11-05
---

# 启用或停用一个新闻来源

PATCH /api/news/sources 按 sourceId 为你的实时流开启或关闭一个新闻来源，其他来源的设置保持不变。成功时返回该来源的最新状态；返回 409 表示该来源当前不可用，暂时无法启用，请稍后再试。

Canonical URL: https://tweetstream.io/zh-cn/docs/api/set-news-source-enabled

## `PATCH /api/news/sources`

`https://api.tweetstream.io/api/news/sources`

## 授权

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `Authorization` | `string`, 必填 | 使用 TweetStream API 密钥进行 Bearer 认证：`Bearer <key>`。 |

## 请求体

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `enabled` | `boolean`, 必填 |  |
| `sourceId` | `string`, 必填 |  |

### 请求体示例

```json
{
  "enabled": true,
  "sourceId": "bbc-news"
}
```

## 响应字段

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `source` | `object`, 必填 |  |
| `source.available` | `boolean`, 必填 |  |
| `source.enabled` | `boolean`, 必填 |  |
| `source.icon` | `string`, 必填 |  |
| `source.id` | `string`, 必填 |  |
| `source.name` | `string`, 必填 |  |

## 响应

| 状态 | 说明 | 请求头 |
| --- | --- | --- |
| `200` | 成功 |  |
| `400` | 请求无效 |  |
| `401` | API key 缺失或无效 |  |
| `403` | 已认证的账号无法使用此功能 |  |
| `409` | 该来源当前不可用 |  |
| `500` | 请求未能完成 |  |

### 200

```json
{
  "source": {
    "available": true,
    "enabled": true,
    "icon": "<string>",
    "id": "<string>",
    "name": "<string>"
  }
}
```

### 400

```json
{
  "error": "<string>"
}
```

### 401

```json
{
  "error": "<string>"
}
```

### 403

```json
{
  "error": "<string>"
}
```

### 409

```json
{
  "error": "<string>"
}
```

### 500

```json
{
  "error": "<string>"
}
```

## 代码示例

### cURL

```bash
curl --request PATCH \
  --url https://api.tweetstream.io/api/news/sources \
  --header "Authorization: Bearer $TWEETSTREAM_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "enabled": true,
  "sourceId": "bbc-news"
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.tweetstream.io/api/news/sources", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.TWEETSTREAM_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "enabled": true,
    "sourceId": "bbc-news"
  }),
});

console.log(response.status, await response.json());
```

### Python

```python
import os
import requests

response = requests.patch(
    "https://api.tweetstream.io/api/news/sources",
    headers={"Authorization": f"Bearer {os.environ['TWEETSTREAM_API_KEY']}"},
    json={
        "enabled": True,
        "sourceId": "bbc-news",
    },
)

print(response.status_code, response.json())
```
