TIBCO Data Virtualization で Spotify のデータ にリアルタイムアクセスする方法
TIBCO Data Virtualization(TDV)は、複数の多様なデータソースへのアクセスを一元管理するエンタープライズデータ仮想化ソリューションです。CData TIBCO DV Adapter for Spotify と組み合わせることで、TIBCO Data Virtualization 内からSpotify のデータに直接フェデレーテッドアクセスが可能になります。この記事では、アダプターのデプロイと Spotify に基づく新しいデータソースの作成手順を解説します。
CData TIBCO DV Adapter は、最適化されたデータ処理機能が組み込まれており、Spotify のデータ とのインタラクションにおいて比類のないパフォーマンスを発揮します。Spotify に対して複雑な SQL クエリを発行すると、アダプターはフィルタや集計などサポートされている SQL 操作を直接 Spotify にプッシュします。組み込みの動的メタデータクエリにより、ネイティブのデータ型を使用してSpotify のデータを操作・分析できます。
Spotify TIBCO DV Adapter のデプロイ
コンソールで、TDV Server のインストールディレクトリ内の bin フォルダに移動します。現在のバージョンのアダプターがインストールされている場合は、先にアンデプロイする必要があります。
.\server_util.bat -server localhost -user admin -password ******** -undeploy -version 1 -name API
CData TIBCO DV Adapter をローカルフォルダに解凍し、解凍した場所から JAR ファイル(tdv.api.jar)をサーバーにデプロイします。
.\server_util.bat -server localhost -user admin -password ******** -deploy -package /PATH/TO/tdv.api.jar
新しい JAR ファイルが正しくロードされるように、サーバーの再起動が必要な場合があります。再起動は、C:\Program Files\TIBCO\TDV Server <version>\bin にある composite.bat スクリプトを実行して行えます。サーバーを再起動した後は、TDV Studio への再認証が必要です。
再起動コマンドの例
.\composite.bat monitor restart
OAuth を使用して Spotify で認証する
Spotify は OAuth プロトコルを使用して認証を行いますが、TDV Studio は内部でブラウザベースの認証をサポートしていないため、OAuth トークンを取得するための簡単な Java アプリケーションを作成して実行する必要があります。取得したトークンは、アダプターから直接 Spotify に接続するために使用されます。
Create the Java Application
- Create a new Java file with preferred name for example GenOAuthSettings.java. This Java file leverages the APIOAuth class contained within the TDV Adapter JAR to initiate a test connection and perform the required OAuth authentication flow
- Copy and insert the following code into the .java file:
- Place the .java file in the same directory as the tdv.api.jar file. This is required to prevent classpath resolution errors during compilation and execution
public class GenOAuthSettings {
public static void main(String[] args) {
try {
if (args.length != 2) {
throw new Exception("Input must have two arguments: 'data source', 'connection string'");
}
String source = args[0].replace(" ", "").toLowerCase();
String connectionString = args[1];
String prefix;
if (source.equals("api")) {
prefix = "jdbc:api:";
com.cdata.cis.api.APIOAuth oauth = new com.cdata.cis.api.APIOAuth();
if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
oauth.generateOAuthSettingsFile(connectionString);
}
// More sources can be added below using the same format. You must add the import statement and ensure the jar file resides in the classpath
// else if (source.equals("googlebigquery") || source.equals("bigquery")) {
// prefix = "jdbc:googlebigquery:";
//
// com.cdata.cis.googlebigquery.GoogleBigQueryOAuth oauth = new com.cdata.cis.googlebigquery.GoogleBigQueryOAuth();
//
// if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
// oauth.generateOAuthSettingsFile(connectionString);
// }
else {
throw new Exception("Data Source not supported. Available Data Sources: Spotify");
}
System.out.println("Test Connection Successful!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Build and run the Java Application
- Open Console and navigate to the directory containing the .java file and adapter jar
- Compile the Java file using the following command:
- Execute the application using one of the following commands:
javac -cp .;tdv.api.jar GenOAuthSettings.java
java -cp .;tdv.api.jar GenOAuthSettings "API" "connection string"
This command initiates the OAuth authentication flow and generates the OAuth settings file at the location specified in the OAuthSettingsLocation parameter. Once you deploy the adapter and authenticate, you can create a new data source for Spotify in TDV Studio.
TDV Studio で Spotify データソースを作成する
CData TIBCO DV Adapter for Spotify を使用すると、Spotify 用のデータソースを簡単に作成し、データソースをイントロスペクトしてリソースを TDV に追加できます。
データソースの作成
- データソースを追加するフォルダを右クリックし、New -> New Data Source を選択します。
- アダプター(例:Spotify)が表示されるまでスクロールし、Next をクリックします。
- データソースに名前を付けます(例:CData Spotify Source)。
必要な接続プロパティを入力します。
OAuth 認証の設定
Spotify は認証に OAuth 2.0 を使用します。クライアント認証情報を取得するには、Spotify Developer Dashboard でアプリケーションを作成する必要があります。
Spotify アプリケーションのセットアップ
- Spotify Developer Dashboard にアクセスします。
- Spotify アカウントでログインして Create app をクリックします。
- アプリ名、説明を入力し、Redirect URI を設定します(デスクトップアプリケーションの場合は
http://localhost:33333
など)。 - アプリ設定から Client ID と Client Secret をコピーします。
接続プロパティ
以下の接続プロパティを設定して接続を確立してください:
- AuthScheme:OAuth に設定します。
- InitiateOAuth:GETANDREFRESH に設定します。InitiateOAuth を使うと、OAuthAccessToken を取得するプロセスを管理できます。
- OAuthClientId:Spotify アプリケーションの Client ID に設定します。
- OAuthClientSecret:Spotify アプリケーションの Client Secret に設定します。
- Scope:必要な OAuth スコープ(スペース区切り)に設定します。デフォルトには、このプロファイルのテーブルに必要なすべての読み取りスコープが含まれます。
- CallbackURL:Spotify アプリケーションで設定したリダイレクト URI に設定します(例:http://localhost:33333)。
接続文字列の例
Profile=C:\profiles\Spotify.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=http://localhost:33333;
利用可能な OAuth スコープ
- user-read-private:ユーザーのサブスクリプション詳細と露骨なコンテンツ設定への読み取りアクセス。
- user-read-email:ユーザーのメールアドレスへの読み取りアクセス。
- user-library-read:ユーザーが保存したトラック、アルバム、エピソード、ショー、オーディオブックへの読み取りアクセス。
- playlist-read-private:ユーザーの非公開プレイリストへの読み取りアクセス。
- playlist-read-collaborative:ユーザーがフォローしているコラボレーティブプレイリストへの読み取りアクセス。
- user-follow-read:現在のユーザーがフォローしているアーティストの一覧への読み取りアクセス。
- user-read-playback-state:ユーザーのプレーヤー状態(デバイス、現在のトラック、再生位置)への読み取りアクセス。
- user-read-currently-playing:ユーザーが現在再生中のコンテンツへの読み取りアクセス。
- user-read-playback-history:ユーザーが最近再生したトラックへの読み取りアクセス。
- user-top-read:ユーザーのトップアーティストとトラックへの読み取りアクセス。
NOTE:DV Adapter の OAuthSettingsLocation プロパティには、OAuth 認証(上記参照)を実行したときと同じ値を設定してください。
- Create & Close をクリックします。
データソースのイントロスペクト
データソースを作成したら、右クリックして Open を選択することでデータソースをイントロスペクトできます。ダッシュボードで Add/Remove Resources をクリックし、データソースの一部として含めるテーブル、ビュー、ストアドプロシージャを選択します。Next をクリックし、Finish をクリックして、選択した Spotify のテーブル、ビュー、ストアドプロシージャをリソースとして追加します。
After creating and introspecting the data source, you are ready to work with Spotify のデータ in TIBCO Data Virtualization just like you would any other relational data source. You can create views, query using SQL, publish the data source, and more.
データソースを作成してイントロスペクトしたら、他のリレーショナルデータソースと同様に TIBCO Data Virtualization でSpotify のデータを操作できるようになります。ビューの作成、SQL によるクエリ、データソースの公開など、さまざまな操作が可能です。