Twitterウィジットの JavaScript ライブラリは、twttr.widgets.createVideo 関数を使って、埋め込み型動画の動的挿入をサポートしています。 動画のツイート ID、対象となる親エレメント、任意のカスタムオプションを引数として渡してください。
このページのコードは、あなたのページでTwitterの widgets.jsの読み込みが成功していることを前提に書かれています。 JavaScript loader のドキュメントで説明しているように、 window.twttrを初期化している間に、あなたのページにscript loader を非同期でインクルードしてください。widgets.jsに依存する全てのJavaScript コードは、 twitter.ready上か twitter.readyの後に実行しなければなりません。
Embedded Video JavaScript Factory FunctionTwitter’s widget JavaScript library supports dynamic insertion of Embedded Videos using the The code snippets on this page assume Twitter’s |
オリジナルの動画を含んでいるツイートの数値型ID。
サンプル値: '560070183650213889'
希望する挿入ポイントのDOM ノード。
サンプル値: document.getElementById('container')
Arguments
tweetID
required
The numerical ID of the Tweet containing the original video. Example Value:
targetEl
required
DOM node of the desired insertion point. Example Value:
options
optional
Override default widget options. See Embedded Video parameter reference for details. Example Value: |
ページに、containerのDOM IDが付いたエレメントがあるとします。
<div id="container"></div>
以下のコードでは、Tweet ID 560070183650213889の動画をユニークIDがcontainerのエレメント内に挿入します。 このオプションオブジェクトではツイート設定の非表示(ダイレクトリンク)を設定しています。
twttr.widgets.createVideo(
'560070183650213889',
document.getElementbyId('container'),
{
status: 'hidden'
}
);
ExampleAn element with a DOM ID of <div id="container"></div> The code snippet below will insert the video from Tweet ID 560070183650213889 into a page inside an element with a unique ID of twttr.widgets.createVideo(
'560070183650213889',
document.getElementbyId('container'),
{
status: 'hidden'
}
);
|
twttr.widgets.createVideo関数は、 Promiseオブジェクトを戻り値として返します。 戻り値として取得するpromiseオブジェクトのthen関数にコールバック関数を渡すことで、ウィジットがあなたのページに埋め込まれた後にそのコードを実行することができます。
twttr.widgets.createVideo(...)
.then( function( el ) {
console.log('Video added.');
});
PromisesThe twttr.widgets.createVideo(...)
.then( function( el ) {
console.log('Video added.');
});
|