News Volume API について
News Volume API は、トピックに関するニュース記事の言及量を時系列、成長率、ライブデータで提供します。開発者やメディア分析担当者は、Python、JavaScript/TypeScript クライアントまたは HTTP から利用できます。
主な機能
- 01ニュース言及量の時系列
- 02期間指定による成長率
- 03ページネーション付きライブトレンド
- 04Python と JavaScript/TypeScript クライアント
- 05Pandas でのデータ処理
活用シーン
- 01トピックに関する記事の言及量の監視
- 02リアルタイムのニューストレンド確認
- 03期間別の言及量成長の比較
設定
リモートサーバーはインストール不要です。クライアントを選んで設定をコピーするか、ワンクリックで導入できます。
https://news-volume.api.trendsapi.ai/mcpclaude mcp add --transport http ai-trendsapi-news-volume https://news-volume.api.trendsapi.ai/mcp{"mcpServers":{"ai-trendsapi-news-volume":{"type":"http","url":"https://news-volume.api.trendsapi.ai/mcp"}}}Cursor で開く{"servers":{"ai-trendsapi-news-volume":{"type":"http","url":"https://news-volume.api.trendsapi.ai/mcp"}}}VS Code で開く{"mcpServers":{"ai-trendsapi-news-volume":{"type":"http","url":"https://news-volume.api.trendsapi.ai/mcp"}}}{"mcpServers":{"ai-trendsapi-news-volume":{"serverUrl":"https://news-volume.api.trendsapi.ai/mcp"}}}コマンドはターミナルで実行し、JSON は各クライアントの MCP 設定に貼り付けて再起動します。認可が必要なサーバーは初回接続時にログインを求めます。
https://news-volume.api.trendsapi.ai/mcp認証が必要ツール
詳細
ニュースの言及量 API
Trends API によるニュースの言及量です。ニュースサイトをスクレイピングせずにメディアをモニタリングできます。
キー:trendsapi.ai/#get-key。HTTP の仕様とすべてのソース:trendsapi-ai/trendsapi。
認証
pip install news-trends-api
export TRENDSAPI_KEY=your_key
Python 3.9 以降。同じキーを HTTP API に使用します。
from news_trends_api import TrendsAPI
client = TrendsAPI() # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")
キーワードヘルパーのデフォルトは source: "news volume" です。同じクライアントで他のプラットフォームを利用するには、source= を渡してください。公式のフルクライアント(すべてのソースに対応し、プリセットなし):trendsapi。
メソッド
| メソッド | REST mode | 戻り値 |
|---|---|---|
get_time_series(keyword, source=, data_mode=) | get_time_series | list[TrendsDataPoint] |
get_growth(keyword, percent_growth=, source=, data_mode=) | get_growth | GetGrowthResponse |
get_live(limit=, offset=, category=) | get_top_trends | GetTopTrendsResponse |
get_top_trends(type=, ...) | get_top_trends | GetTopTrendsResponse |
source は小文字です(news volume)。type は正確な値を指定してください(Google News Top News)。両方を混在させると 400 エラーになります。
from news_trends_api import TrendsAPI
client = TrendsAPI() # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")
series = client.get_time_series("federal reserve")
print(series[-1].date, series[-1].value)
growth = client.get_growth("federal reserve", percent_growth=["3M", "12M"])
print(growth.results[0].growth, growth.results[0].direction)
hot = client.get_live(limit=10)
print(hot.data) # [[1, "..."], ...]
get_time_series
points = client.get_time_series("federal reserve")
各データポイント:
| フィールド | 常に含まれる | 意味 |
|---|---|---|
date | はい | YYYY-MM-DD |
value | はい | この系列の 0~100 のインデックス |
keyword | はい | 指定したキーワード |
volume | いいえ | 利用可能な場合の絶対量 |
source or datatype | いいえ | パイプラインのラベル |
Python では list[TrendsDataPoint] が返されます。["date"] ではなく .date と .value を使用してください。
JS では、同じフィールドがオブジェクトのプロパティとして返されます。
get_growth
g = client.get_growth("federal reserve", percent_growth=["12M", "3M", "YTD"])
print(g.results[0].growth, g.results[0].direction)
percent_growth のデフォルト値:["12M"]。プリセット:7D 14D 30D 1M 2M 3M 6M 9M 12M/1Y 18M 24M/2Y 36M/3Y 48M 60M/5Y MTD QTD YTD。カスタム値:{"name": "Launch", "recent": "2024-06-01", "baseline": "2024-01-01"}。
| フィールド | 意味 |
|---|---|
search_term | キーワード |
data_source | ソース |
results | 各期間につき 1 つのオブジェクト(period、growth、direction、日付、値) |
metadata | 件数/成功フラグ |
複数の期間を指定しても、リクエスト数は 1 件です。Python:growth.results[0].growth。JS:growth.results[0].growth。
get_live
hot = client.get_live(limit=10)
| フィールド | 意味 |
|---|---|
as_of_ts | スナップショットの時刻 |
type | フィード名 |
limit, offset, count | ページネーション |
data | [rank, label] の行 |
Python:hot.data。JS:hot.data。offset= と category= は任意です(Amazon Best Sellers by Category、Top Websites のみ)。
非同期
import asyncio
from news_trends_api import AsyncTrendsAPI
async def main():
c = AsyncTrendsAPI()
return await asyncio.gather(
c.get_time_series("federal reserve"),
c.get_time_series("federal reserve", source="google search"),
)
asyncio.run(main())
HTTP 200 の応答 1 件につき、課金対象のリクエストは 1 件です。
Pandas
from dataclasses import asdict
import pandas as pd
from news_trends_api import TrendsAPI
df = pd.DataFrame(asdict(p) for p in TrendsAPI().get_time_series("federal reserve"))
df["date"] = pd.to_datetime(df["date"])
print(df.set_index("date")["value"].resample("ME").mean().tail())
JavaScript / TypeScript
npm install news-trends-api
Node 18 以降、Deno、Bun、Workers に対応しています。同じ API キーを使用します。上記のフィールド表が適用されます。
メソッド
| メソッド | REST mode | 戻り値 |
|---|---|---|
getTimeSeries(keyword, { source, data_mode }) | get_time_series | 週ごとのデータポイント |
getGrowth(keyword, { percent_growth, source, data_mode }) | get_growth | 成長オブジェクト |
getLive({ limit, offset, category }) | get_top_trends | ライブフィード |
getTopTrends({ type, ... }) | get_top_trends | ライブフィード |
import { TrendsAPI } from "news-trends-api";
const client = new TrendsAPI({ apiKey: process.env.TRENDSAPI_KEY! });
const series = await client.getTimeSeries("federal reserve");
console.log(series.at(-1)?.date, series.at(-1)?.value);
const growth = await client.getGrowth("federal reserve", {
percent_growth: ["3M", "12M"],
});
console.log(growth.results[0].growth, growth.results[0].direction);
const live = await client.getLive({ limit: 10 });
console.log(live.data); // [[1, "..."], ...]
呼び出し(curl)
| フィールド | 値 |
|---|---|
| エンドポイント | POST https://api.trendsapi.ai/api |
| 認証 | Authorization: Bearer $TRENDSAPI_KEY |
| 履歴データ | get_time_series または get_growth と source: news volume |
| キーワード | 任意の語句(例:federal reserve) |
ライブ type | Google News Top News |
curl -sS -X POST https://api.trendsapi.ai/api \
-H "Authorization: Bearer $TRENDSAPI_KEY" \
-H "Content-Type: application/json" \
--max-time 60 \
-d '{"mode":"get_time_series","source":"news volume","keyword":"federal reserve"}'
ソースに関する注意
- このソースは応答が遅い場合があります。HTTP 504 の HTML 応答は課金対象ではありません。再試行してください。
source: news sentimentはトーンを示すもので、言及数ではありません。
エラー
| HTTP | クライアント |
|---|---|
| 200 | ペイロードを解析しました。Python のデータクラス/JS の型付きオブジェクト |
| 400 | エラーが発生します。source または type のスペルを修正してください |
| 401 | エラーが発生します。TRENDSAPI_KEY を確認してください |
| 404 | エラーが発生します。そのキーワードの系列はありません。再試行しないでください |
| 429 | エラーが発生します。クォータ |
| 5xx | クライアントが再試行した後、エラーが発生します |
HTTP の body フィールドは JSON 文字列です。SDK はこれをデコードします。生の curl では、body をもう一度解析する必要があります。
サイト:https://trendsapi.ai/trends/news-trends。
ライセンス
MIT。LICENSE を参照してください。
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。