## 如何使用CNN API:轻松获取新闻
**CNN API**允许开发者访问全球领先新闻机构之一CNN的实时新闻通过利用此API,您可以检索分类新闻故事,获取特定文章的详细报道,并随时了解政治、商业、健康和娱乐等各个领域的最新新闻本文将提供有关如何使用各种方法调用CNN API的全面指南,突出使用该API的创意想法,并涵盖该API的好处和特点
---
### 什么是CNN API
**CNN API**可以通过RapidAPI平台访问,允许访问CNN的最新新闻头条和详细文章它简化了从**美国**、**世界**、**政治**、**娱乐**等类别中检索新闻文章的过程可以调用API来提取简短头条和包含图像、描述和视频的完整文章详细信息
---
### 主要特点和好处
1. **获取实时新闻**:获取各类最新突发新闻
2. **易于集成**:该API基于REST构建,便于与任何支持HTTP请求的系统集成
3. **详细新闻文章**:详情端点提供丰富的信息,如图像、头条、描述、字数,甚至相关视频
4. **灵活性**:API允许您按类别过滤新闻,确保您获取对受众最相关的新闻
5. **多媒体支持**:不仅检索基于文本的新闻,还可获取相关图像和嵌入视频
6. **用例多样性**:无论您是构建新闻聚合应用、新闻聊天机器人,还是仅需为您的网站提供最新头条,CNN API都是您首选的工具
---
### 如何调用CNN API
#### 示例1:按类别获取新闻
您可以使用以下cURL命令按类别获取最新新闻:
```bash
curl --request GET \
--url 'https://cnn-api.p.rapidapi.com/category?url=https%3A%2F%2Fedition.cnn.com%2Fentertainment' \
--header 'x-rapidapi-host: cnn-api.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY'
```
此命令从CNN检索最新的娱乐新闻您可以用其他类别链接替换URL,从而检索其他部分的新闻,如**世界**、**美国**、**政治**或**健康**
##### 类别示例:
- 美国:`https://edition.cnn.com/us`
- 世界:`https://edition.cnn.com/world`
- 政治:`https://edition.cnn.com/politics`
- 商业:`https://edition.cnn.com/business`
- 健康:`https://edition.cnn.com/health`
---
#### 示例2:获取详细新闻文章
要深入了解特定文章,请使用“详情”端点以下是您如何检索标题、描述、图像、视频和文章正文等详细信息:
```bash
curl --request GET \
--url 'https://cnn-api.p.rapidapi.com/details?url=https%3A%2F%2Fedition.cnn.com%2F2024%2F07%2F08%2Fpolitics%2Fbiden-fate-political-career%2Findex.html' \
--header 'x-rapidapi-host: cnn-api.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY'
```
响应提供:
- **标题**:文章标题
- **描述**:文章的简要摘要
- **图像**:缩略图和主图像
- **视频链接**:与故事相关的嵌入视频
- **字数**:文章的总字数
- **文章正文**:文章的完整内容
##### 示例响应(缩短版):
```json
{
"headline": "拜登的命运在他政治生涯中最关键的日子里岌岌可危",
"description": "即将到来的高风险一周至关重要...",
"thumbnailUrl": "https://media.cnn.com/api/v1/images/stellar/prod/gettyimages-2159959397.jpg",
"articleBody": "即将到来的高风险一周对总统乔·拜登的..."
}
```
---
### 使用CNN API的创意
#### 1. **新闻聚合网站**
如果您正在开发新闻聚合平台,可以使用CNN API实时获取头条新闻通过从不同类别(例如政治、健康、商业)中提取文章,您可以让读者掌握各个领域的最新动态
#### 2. **基于新闻的移动应用**
创建一个提供突发新闻和更新的移动应用使用推送通知提醒用户何时有新文章在特定类别中,例如体育或娱乐
#### 3. **智能助手**
将CNN API与语音启用的智能助手如Alexa或Google Assistant集成,为用户提供随需获取的新闻更新
#### 4. **定制新闻简报**
使用API为您的受众策划每日或每周电子邮件新闻简报您可以按与他们兴趣相关的类别过滤文章,并在他们的收件箱中提供最新新闻
#### 5. **聊天机器人**
创建一个智能聊天机器人,可以回答用户关于时事的查询,检索最新新闻文章,并分享突发头条适用于客户服务平台或互动媒体机器人
---
### 结论
CNN API是开发者将实时新闻内容集成到其应用、网站或服务中的优秀工具凭借简单、用户友好的设计和广泛的分类,它非常适合各种用例无论您是在构建新闻应用、简报还是聊天机器人,CNN API都能帮助您让受众掌握CNN广泛内容库中的最新头条和详细报道
请务必探索其全部潜力,通过根据类别定制请求和获取详细文章,提供全面的新闻体验
详细新闻 - 端点功能
| 对象 | 描述 |
|---|---|
url |
[必需] |
{
"url": "https:\/\/edition.cnn.com\/2024\/10\/23\/entertainment\/martha-stewart-golden-bachelorette\/index.html",
"headline": "Martha Stewart has the funniest reason for not wanting to do \u00e2\u0080\u0098The Golden Bachelorette\u00e2\u0080\u0099 | CNN",
"description": "Martha Stewart may be hot in the kitchen, but she\u00e2\u0080\u0099s not looking to replicate that on a dating reality show.",
"image": "https:\/\/media.cnn.com\/api\/v1\/images\/stellar\/prod\/gettyimages-2178806460.jpg?c=16x9&q=w_800,c_fill",
"author": "Lisa Respers France",
"datePublished": "2024-10-23T13:19:27.261Z",
"dateModified": "2024-10-23T13:19:27.261Z",
"section": "2024",
"site_name": "CNN",
"locale": "en_US",
"keywords": "",
"tags": [
""
]
}
curl --location --request GET 'https://zylalabs.com/api/6437/cnn+api/9263/details+news?url=https://edition.cnn.com/2024/10/23/entertainment/martha-stewart-golden-bachelorette/index.html' --header 'Authorization: Bearer YOUR_API_KEY'
按类别的新闻 - 端点功能
| 对象 | 描述 |
|---|---|
url |
[必需] |
{
"category": "top",
"page": 1,
"per_page": 10,
"total_pages": 7,
"total_items": 69,
"items": [
{
"headline": "Some on-air claims about Dominion Voting Systems were false, Fox News acknowledges in statement after deal is announced",
"description": "",
"link": "https:\/\/www.cnn.com\/business\/live-news\/fox-news-dominion-trial-04-18-23\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/fox-news-dominion-trial-04-18-23-large-169.jpg",
"pubDate": "Wed, 19 Apr 2023 12:44:51 GMT"
},
{
"headline": "Dominion still has pending lawsuits against election deniers such as Rudy Giuliani and Sidney Powell",
"description": "",
"link": "https:\/\/www.cnn.com\/business\/live-news\/fox-news-dominion-trial-04-18-23\/h_8d51e3ae2714edaa0dace837305d03b8",
"image": "",
"pubDate": ""
},
{
"headline": "Here are the 20 specific Fox broadcasts and tweets Dominion says were defamatory",
"description": "\u2022 Fox-Dominion trial delay 'is not unusual,' judge says\n\u2022 Fox News' defamation battle isn't stopping Trump's election lies",
"link": "https:\/\/www.cnn.com\/2023\/04\/17\/media\/dominion-fox-news-allegations\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/dominion-fox-news-allegations-large-169.jpg",
"pubDate": "Mon, 17 Apr 2023 16:01:11 GMT"
},
{
"headline": "Judge in Fox News-Dominion defamation trial: 'The parties have resolved their case'",
"description": "The judge just announced in court that a settlement has been reached in the historic defamation case between Fox News and Dominion Voting Systems.",
"link": "https:\/\/www.cnn.com\/2023\/04\/18\/media\/fox-dominion-settlement\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/fox-dominion-settlement-large-169.jpg",
"pubDate": "Wed, 19 Apr 2023 08:28:17 GMT"
},
{
"headline": "'Difficult to say with a straight face': Tapper reacts to Fox News' statement on settlement",
"description": "A settlement has been reached in Dominion Voting Systems' defamation case against Fox News, the judge for the case announced. The network will pay more than $787 million to Dominion, a lawyer for the company said.",
"link": "https:\/\/www.cnn.com\/videos\/politics\/2023\/04\/18\/jake-tapper-dominion-lawsuit-settlement-fox-news-statement-lead-vpx.cnn",
"image": "",
"pubDate": "Tue, 18 Apr 2023 21:17:44 GMT"
},
{
"headline": "Millions in the US could face massive consequences unless McCarthy can navigate out of a debt trap he set for Biden",
"description": "\u2022 DeSantis goes to Washington, a place he once despised, looking for support to take on Trump\n\u2022 Opinion: For the GOP to win, it must ditch Trump\n\u2022 Chris Christie mulling 2024 White House bid\n\u2022 Analysis: The fire next time has begun burning in Tennessee ",
"link": "https:\/\/www.cnn.com\/2023\/04\/18\/politics\/mccarthy-biden-debt-ceiling\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/mccarthy-biden-debt-ceiling-large-169.jpg",
"pubDate": "Tue, 18 Apr 2023 20:34:45 GMT"
},
{
"headline": "White homeowner accused of shooting a Black teen who rang his doorbell turns himself in to face criminal charges",
"description": "\u2022 'A major part of Ralph died': Aunt of teen shot after ringing wrong doorbell speaks\n\u2022 20-year-old woman shot after friend turned into the wrong driveway in upstate New York, officials say",
"link": "https:\/\/www.cnn.com\/2023\/04\/18\/us\/kansas-city-ralph-yarl-shooting-tuesday\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/kansas-city-ralph-yarl-shooting-tuesday-large-169.jpg",
"pubDate": "Wed, 19 Apr 2023 04:29:05 GMT"
},
{
"headline": "Newly released video shows scene of Jeremy Renner's snowplow accident",
"description": "Newly released body camera footage shows firefighters and sheriff's deputies rushing to help actor Jeremy Renner after a near-fatal snowplow accident in January. The \"Avengers\" actor broke more than 30 bones and suffered other severe injuries. CNN's Chloe Melas has more. ",
"link": "https:\/\/www.cnn.com\/videos\/us\/2023\/04\/18\/jeremy-renner-snowplow-accident-bodycam-nc-melas-contd-vpx.cnn",
"image": "",
"pubDate": "Tue, 18 Apr 2023 14:09:43 GMT"
},
{
"headline": "Jake Gyllenhaal and Jamie Lee Curtis spent the Covid-19 lockdown together",
"description": "It's sourdough bread and handstands for Jake Gyllenhaal and Jamie Lee Curtis.",
"link": "https:\/\/www.cnn.com\/2023\/04\/18\/entertainment\/jake-gyllenhaal-jamie-lee-curtis-pandemic-living\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/jake-gyllenhaal-jamie-lee-curtis-pandemic-living-large-169.jpg",
"pubDate": "Tue, 18 Apr 2023 14:40:32 GMT"
},
{
"headline": "Toddler crawls through White House fence, prompts Secret Service response",
"description": "A tiny intruder infiltrated White House grounds Tuesday, prompting a swift response from the US Secret Service.",
"link": "https:\/\/www.cnn.com\/2023\/04\/18\/politics\/white-house-toddler\/index.html",
"image": "https:\/\/cdn.cnn.com\/cnnnext\/dam\/assets\/white-house-toddler-large-169.jpg",
"pubDate": "Tue, 18 Apr 2023 17:38:16 GMT"
}
],
"available_categories": [
"top",
"world",
"us",
"politics",
"business",
"tech",
"health",
"entertainment",
"travel",
"sports",
"opinion",
"justice",
"weather",
"latest",
"europe",
"asia",
"africa",
"middleeast",
"americas",
"energy",
"space",
"food",
"style",
"living",
"education"
]
}
curl --location --request GET 'https://zylalabs.com/api/6437/cnn+api/9264/news+by+category?url=https://edition.cnn.com/entertainment' --header 'Authorization: Bearer YOUR_API_KEY'
| 标头 | 描述 |
|---|---|
授权
|
[必需] 应为 Bearer access_key. 订阅后,请查看上方的"您的 API 访问密钥"。 |
无长期承诺。随时升级、降级或取消。 免费试用包括最多 50 个请求。
CNN API 有两个主要端点 "按类别获取新闻" 端点返回指定类别文章的标题和链接列表 "获取详细新闻文章" 端点提供有关特定文章的全面细节,包括标题 描述 图片 视频 字数和全文内容
“按类别获取新闻”响应中的关键字段包括“标题”和“链接”“获取详细新闻文章”的重要字段是“标题”“描述”“缩略图链接”“文章内容”和“视频链接”这些字段提供了显示新闻内容的基本信息
响应数据采用JSON格式结构。对于分类端点,它在“latest”键下返回一个文章数组。详细文章端点返回一个包含代表文章不同方面的各种键的单个对象,例如“headline”、“description”和“images”
“按类别获取新闻”接口提供各种类别的头条和文章链接,如美国、世界、政治等。“获取详细新闻文章”接口提供特定文章的深入信息,包括多媒体元素和完整文本主体
这两个端点的主要参数是“url”参数,它指定了您想要检索的CNN文章或类别的URL。用户可以通过更改URL来自定义其请求,以针对不同的新闻类别或特定文章
用户可以在新闻聚合网站或应用程序上显示来自分类端点的头条和链接。详细的文章数据可以用于创建丰富的内容展示,包括图像和摘要,从而增强用户与多媒体元素的互动
典型的使用案例包括建立新闻聚合网站 开发移动新闻应用程序 创建定制新闻通讯以及与聊天机器人或智能助手集成 为用户提供实时新闻更新以满足他们的兴趣
CNN API直接从知名新闻机构CNN获取数据 通过CNN编辑团队定期更新和质量检查来保持数据的准确性 确保提供的信息可靠且最新
服务级别:
100%
响应时间:
55ms
服务级别:
100%
响应时间:
12,696ms
服务级别:
100%
响应时间:
7,928ms
服务级别:
100%
响应时间:
99ms
服务级别:
100%
响应时间:
350ms
服务级别:
100%
响应时间:
869ms
服务级别:
100%
响应时间:
1,645ms
服务级别:
100%
响应时间:
378ms
服务级别:
100%
响应时间:
479ms
服务级别:
100%
响应时间:
1,284ms