Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

クリエイターを管理する

最終更新 Markdown で表示Agent セットアップ

トークン化したアップロード URL をリクエストするときに、内部ユーザー ID を creator フィールドへ設定できます。動画がアップロードされると、creator プロパティはその内部ユーザー ID に自動で設定されます。分析データや、特定クリエイターの動画検索に使えます。

基本アップロードでは、動画のアップロード後に Creator ID を追加する必要があります。

URL からアップロードする

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/stream/copy" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"url":"https://example.com/myvideo.mp4","creator": "<CREATOR_ID>","thumbnailTimestampPct":0.529241,"allowedOrigins":["example.com"],"requireSignedURLs":true,"watermark":{"uid":"ea95132c15732412d22c1476fa83f27a"}}'
const client = new Cloudflare({
	apiEmail: process.env['CLOUDFLARE_EMAIL'],
	apiKey: process.env['CLOUDFLARE_API_KEY'],
});

const video = await client.stream.copy.create({
	account_id: '<ACCOUNT_ID>',
	url: 'https://example.com/myvideo.mp4',
	creator: '<CREATOR_ID>',
	thumbnailTimestampPct: 0.529241,
	allowedOrigins: ['example.com'],
	requireSignedURLs: true,
	watermark: { uid: 'ea95132c15732412d22c1476fa83f27a' },
});

応答

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"allowedOrigins": ["example.com"],
		"created": "2014-01-02T02:20:00Z",
		"duration": 300,
		"input": {
			"height": 1080,
			"width": 1920
		},
		"maxDurationSeconds": 300,
		"meta": {},
		"modified": "2014-01-02T02:20:00Z",
		"uploadExpiry": "2014-01-02T02:20:00Z",
		"playback": {
			"hls": "https://customer-f33zs165nr7gyfy4.cloudflarestream.com/6b9e68b07dfee8cc2d116e4c51d6a957/manifest/video.m3u8",
			"dash": "https://customer-f33zs165nr7gyfy4.cloudflarestream.com/6b9e68b07dfee8cc2d116e4c51d6a957/manifest/video.mpd"
		},
		"preview": "https://customer-f33zs165nr7gyfy4.cloudflarestream.com/6b9e68b07dfee8cc2d116e4c51d6a957/watch",
		"readyToStream": true,
		"requireSignedURLs": true,
		"size": 4190963,
		"status": {
			"state": "ready",
			"pctComplete": "100.000000",
			"errorReasonCode": "",
			"errorReasonText": ""
		},
		"thumbnail": "https://customer-f33zs165nr7gyfy4.cloudflarestream.com/6b9e68b07dfee8cc2d116e4c51d6a957/thumbnails/thumbnail.jpg",
		"thumbnailTimestampPct": 0.529241,
		"creator": "<CREATOR_ID>",
		"uid": "6b9e68b07dfee8cc2d116e4c51d6a957",
		"liveInput": "fc0a8dc887b16759bfd9ad922230a014",
		"uploaded": "2014-01-02T02:20:00Z",
		"watermark": {
			"uid": "6b9e68b07dfee8cc2d116e4c51d6a957",
			"size": 29472,
			"height": 600,
			"width": 400,
			"created": "2014-01-02T02:20:00Z",
			"downloadedFrom": "https://company.com/logo.png",
			"name": "Marketing Videos",
			"opacity": 0.75,
			"padding": 0.1,
			"scale": 0.1,
			"position": "center"
		}
	}
}

外部アプリケーションから REST API を使う方法と、TypeScript、Python、Go 向けの事前生成 SDK の詳細は、Stream の REST API と SDK リファレンス を参照してください。

export default {
	async fetch(request, env) {
		const video = await env.STREAM.upload("https://example.com/myvideo.mp4", {
			creator: "<CREATOR_ID>",
			thumbnailTimestampPct: 0.529241,
			allowedOrigins: ["example.com"],
			requireSignedURLs: true,
			watermarkId: "ea95132c15732412d22c1476fa83f27a",
		});
		return Response.json(video);
	},
};
{
	"$schema": "node_modules/wrangler/config-schema.json",
	"name": "<ENTER_WORKER_NAME>",
	"main": "src/index.ts",
	"compatibility_date": "$today",
	"observability": {
		"enabled": true
	},
	"stream": {
		"binding": "STREAM"
	}
}

Workers Stream binding API リファレンス を参照してください。

動画のデフォルトクリエイターを設定する

デフォルトの creator ID を設定すると、動画を 1 人のクリエイターに紐付けできます。あとから creator ID で動画を検索したり、分析データに使ったりできます。

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/stream/live_inputs" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"defaultCreator":"1234"}'
const client = new Cloudflare({
	apiEmail: process.env['CLOUDFLARE_EMAIL'],
	apiKey: process.env['CLOUDFLARE_API_KEY'],
});

const liveInput = await client.stream.liveInputs.create({
	account_id: '<ACCOUNT_ID>',
	defaultCreator: '1234',
});

外部アプリケーションから REST API を使う方法と、TypeScript、Python、Go 向けの事前生成 SDK の詳細は、Stream の REST API と SDK リファレンス を参照してください。

ライブストリームを開始するクリエイターが複数いる場合は、ライブ配信するクリエイターごとに ライブ入力を作成 し、入力ごとに DefaultCreator を設定します。入力ごとにデフォルトの creator ID を設定すると、そのクリエイターの入力から録画された動画は DefaultCreator の値を引き継ぎます。

現時点では、デフォルトの creator ID は API でのみ管理できます。

既存動画の creator を更新する

既存動画の creator プロパティを更新するには、動画オブジェクトのエンドポイントへ POST リクエストを送り、次の例のように creator プロパティを指定した JSON ペイロードを付けます。

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/stream/<VIDEO_UID>" \
--header "Authorization: Bearer <AUTH_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"creator":"test123"}'
const client = new Cloudflare({
	apiEmail: process.env['CLOUDFLARE_EMAIL'],
	apiKey: process.env['CLOUDFLARE_API_KEY'],
});

const video = await client.stream.edit({
	account_id: '<ACCOUNT_ID>',
	identifier: '<VIDEO_UID>',
	creator: 'test123',
});

外部アプリケーションから REST API を使う方法と、TypeScript、Python、Go 向けの事前生成 SDK の詳細は、Stream の REST API と SDK リファレンス を参照してください。

export default {
	async fetch(request, env) {
		const video = await env.STREAM.video("<VIDEO_UID>").update({
			creator: "test123",
		});
		return Response.json(video);
	},
};
{
	"$schema": "node_modules/wrangler/config-schema.json",
	"name": "<ENTER_WORKER_NAME>",
	"main": "src/index.ts",
	"compatibility_date": "$today",
	"observability": {
		"enabled": true
	},
	"stream": {
		"binding": "STREAM"
	}
}

Workers Stream binding API リファレンス を参照してください。

Direct Creator Upload

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/stream/direct_upload" \
--header "Authorization: Bearer <AUTH_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"maxDurationSeconds":300,"expiry":"2021-01-02T02:20:00Z","creator": "<CREATOR_ID>", "thumbnailTimestampPct":0.529241,"allowedOrigins":["example.com"],"requireSignedURLs":true,"watermark":{"uid":"ea95132c15732412d22c1476fa83f27a"}}'
const client = new Cloudflare({
	apiEmail: process.env['CLOUDFLARE_EMAIL'],
	apiKey: process.env['CLOUDFLARE_API_KEY'],
});

const directUpload = await client.stream.directUpload.create({
	account_id: '<ACCOUNT_ID>',
	maxDurationSeconds: 300,
	expiry: '2021-01-02T02:20:00Z',
	creator: '<CREATOR_ID>',
	thumbnailTimestampPct: 0.529241,
	allowedOrigins: ['example.com'],
	requireSignedURLs: true,
	watermark: { uid: 'ea95132c15732412d22c1476fa83f27a' },
});

応答

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"uploadURL": "www.example.com/samplepath",
		"uid": "ea95132c15732412d22c1476fa83f27a",
		"creator": "<CREATOR_ID>",
		"watermark": {
			"uid": "ea95132c15732412d22c1476fa83f27a",
			"size": 29472,
			"height": 600,
			"width": 400,
			"created": "2014-01-02T02:20:00Z",
			"downloadedFrom": "https://company.com/logo.png",
			"name": "Marketing Videos",
			"opacity": 0.75,
			"padding": 0.1,
			"scale": 0.1,
			"position": "center"
		}
	}
}

外部アプリケーションから REST API を使う方法と、TypeScript、Python、Go 向けの事前生成 SDK の詳細は、Stream の REST API と SDK リファレンス を参照してください。

export default {
	async fetch(request, env) {
		const directUpload = await env.STREAM.createDirectUpload({
			maxDurationSeconds: 300,
			expiry: "2021-01-02T02:20:00Z",
			creator: "<CREATOR_ID>",
			thumbnailTimestampPct: 0.529241,
			allowedOrigins: ["example.com"],
			requireSignedURLs: true,
			watermark: {
				id: "ea95132c15732412d22c1476fa83f27a",
			},
		});
		return Response.json(directUpload);
	},
};
{
	"$schema": "node_modules/wrangler/config-schema.json",
	"name": "<ENTER_WORKER_NAME>",
	"main": "src/index.ts",
	"compatibility_date": "$today",
	"observability": {
		"enabled": true
	},
	"stream": {
		"binding": "STREAM"
	}
}

Workers Stream binding API リファレンス を参照してください。

Creator ID で動画を取得する

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/stream?after=2014-01-02T02:20:00Z&before=2014-01-02T02:20:00Z&include_counts=false&creator=<CREATOR_ID>&limit=undefined&asc=false&status=downloading,queued,inprogress,ready,error" \
--header "Authorization: Bearer <API_TOKEN>"
const client = new Cloudflare({
	apiEmail: process.env['CLOUDFLARE_EMAIL'],
	apiKey: process.env['CLOUDFLARE_API_KEY'],
});

const videos = await client.stream.list({
	account_id: '<ACCOUNT_ID>',
	creator: '<CREATOR_ID>',
});

応答

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": [
		{
			"allowedOrigins": ["example.com"],
			"created": "2014-01-02T02:20:00Z",
			"duration": 300,
			"input": {
				"height": 1080,
				"width": 1920
			},
			"maxDurationSeconds": 300,
			"meta": {},
			"modified": "2014-01-02T02:20:00Z",
			"uploadExpiry": "2014-01-02T02:20:00Z",
			"playback": {
				"hls": "https://customer-<CODE>.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/manifest/video.m3u8",
				"dash": "https://customer-<CODE>.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/manifest/video.mpd"
			},
			"preview": "https://customer-<CODE>.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/watch",
			"readyToStream": true,
			"requireSignedURLs": true,
			"size": 4190963,
			"status": {
				"state": "ready",
				"pctComplete": "100.000000",
				"errorReasonCode": "",
				"errorReasonText": ""
			},
			"thumbnail": "https://customer-<CODE>.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/thumbnails/thumbnail.jpg",
			"thumbnailTimestampPct": 0.529241,
			"creator": "some-creator-id",
			"uid": "ea95132c15732412d22c1476fa83f27a",
			"liveInput": "fc0a8dc887b16759bfd9ad922230a014",
			"uploaded": "2014-01-02T02:20:00Z",
			"watermark": {
				"uid": "ea95132c15732412d22c1476fa83f27a",
				"size": 29472,
				"height": 600,
				"width": 400,
				"created": "2014-01-02T02:20:00Z",
				"downloadedFrom": "https://company.com/logo.png",
				"name": "Marketing Videos",
				"opacity": 0.75,
				"padding": 0.1,
				"scale": 0.1,
				"position": "center"
			}
		}
	],
	"total": "35586",
	"range": "1000"
}

外部アプリケーションから REST API を使う方法と、TypeScript、Python、Go 向けの事前生成 SDK の詳細は、Stream の REST API と SDK リファレンス を参照してください。

tus

Upload-Creator ヘッダーで Creator ID を追加します。詳細は 再開可能な大容量ファイル(tus) を参照してください。

GraphQL で Creator ID を検索する

creator プロパティを設定したあと、GraphQL API で特定のクリエイターに絞り込めます。利用できるメトリクスとフィルターは、一括分析の取得 を参照してください。

役に立ちましたか?