MENU
      VOD Stationの概要

        VOD Stationの概要


        記事の要約

        概要

        VOD Stationは、Object Storageに保存されている大量の映像ファイルをいろいろな画質に簡単にエンコードしたり、HLS/DASHプロトコルでストリーミングしたりできるサービスです。HTTP APIを利用して VOD Stationのすべての機能を制御できます。

        共通の設定

        VOD Station API URL

        https://vodstation.apigw.ntruss.com/api/v2
        HTTP

        リクエストヘッダ

        ヘッダ名説明
        x-ncp-region_codeNAVERクラウドプラットフォームの region code(GETリクエストに含まない)
        x-ncp_region_code:{Region Code}
        x-ncp-apigw-timestamp1970年1月1日00:00:00協定世界時(UTC)からの経過時間をミリ秒(Millisecond)で表し、
        API Gatewayサーバとの時間差が5分以上の場合は無効なリクエストとみなす
        x-ncp-apigw-timestamp:{Timestamp}
        x-ncp-iam-access-keyNAVERクラウドプラットフォームポータルから発行された Access Key ID
        x-ncp-iam-access-key:{Sub Account Access Key}
        x-ncp-apigw-signature-v2Access Key IDとマッピングされる Secret Keyで暗号化した署名
        HMACの暗号化アルゴリズムは HmacSHA256を使用
        x-ncp-apigw-signature-v2:{API Gateway Signature}
        Content-TypeRequest bodyが含まれたリクエストの場合、Content typeを application/jsonにしてリクエスト
        Content-Type: application/json

        認証ヘッダ

        VOD Station APIを使用するには API Gateway認証が必要です。
        API Gateway認証についての詳細説明はNAVERクラウドプラットフォーム APIをご参照ください。

        AUTHPARAMSの作成

        • AUTHPARAMSのリクエスト例
        curl -i -X GET \
           -H "x-ncp-region_code:KR" \
           -H "x-ncp-apigw-timestamp:1505290625682" \
           -H "x-ncp-iam-access-key:D78BB444D6D3C84CA38A" \
           -H "x-ncp-apigw-signature-v2:WTPItrmMIfLUk/UyUIyoQbA/z5hq9o3G8eQMolUzTEo=" \
         'https://vodstation.apigw.ntruss.com/api/v2/channels'
        Plain text
        • Signatureの作成(改行文字は\nを使用)

          • リクエストに合わせて StringToSignを作成し、SecretKeyを HmacSHA256アルゴリズムで暗号化した後、Base64でエンコードします。

          • この値をx-ncp-apigw-signature-v2として使用します。

            リクエストStringToSign
            GET /api/v2/channels?limit=10
            x-ncp-apigw-timestamp={timestamp}
            x-ncp-iam-access-key={accesskey}
            x-ncp-apigw-signature-v2={signature}
            GET /api/v2/channels?limit=10
            {timeStamp}
            {accessKey}
        • サンプルコード

        public String makeSignature() {
            String space = " ";					// 空白
            String newLine = "\n";  				// 改行
            String method = "GET";  				// HTTPメソッド
            String url = "/api/v2/channels?isPage=true";	// ドメインを除く「/」以下の全体 URL(クエリストリングを含む)
            String accessKey = "{accessKey}";		// access key id (from portal or Sub Account)
            String secretKey = "{secretKey}";		// secret key (from portal or Sub Account)
            String timestamp = String.valueOf(System.currentTimeMillis());		// 現在のタイムスタンプ(epoch、millisecond)
        
            String message = new StringBuilder()
                .append(method)
                .append(space)
                .append(url)
                .append(newLine)
                .append(timestamp)
                .append(newLine)
                .append(accessKey)
                .toString();
        
            SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
            Mac mac = Mac.getInstance("HmacSHA256");
            mac.init(signingKey);
        
            byte[] rawHmac = mac.doFinal(message.getBytes("UTF-8"));
            String encodeBase64String = Base64.encodeBase64String(rawHmac);
        
          return encodeBase64String;
        }
        Java
        /*
        https://code.google.com/archive/p/crypto-js/
        https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/crypto-js/CryptoJS%20v3.1.2.zip
        */
        
        /*
        CryptoJS v3.1.2
        code.google.com/p/crypto-js
        (c) 2009-2013 by Jeff Mott. All rights reserved.
        code.google.com/p/crypto-js/wiki/License
        */
        
        
        
        function makeSignature(secretKey, method, url, timestamp, accessKey) {
        	var space = " ";
        	var newLine = "\n";
        
        	var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secretKey); // secret key
        	hmac.update(method);		// HTTPメソッド
        	hmac.update(space);		// 空白
        	hmac.update(url);		// ドメインを除く「/」以下の全体 URL(クエリストリングを含む)
        	hmac.update(newLine);		// 改行
        	hmac.update(timestamp);		// 現在のタイムスタンプ(epoch、millisecond)
        	hmac.update(newLine);		// 改行
        	hmac.update(accessKey);		// access key (from portal or iam)
        
        	var hash = hmac.finalize();
        
        	return hash.toString(CryptoJS.enc.Base64);
        }
        JavaScript
        import sys
        import os
        import hashlib
        import hmac
        import base64
        import requests
        import time
        
        def	make_signature():
        	timestamp = int(time.time() * 1000)
        	timestamp = str(timestamp)				# 現在のタイムスタンプ(epoch、millisecond)
        
        	access_key = "{accessKey}"				# access key id (from portal or Sub Account)
        	secret_key = "{secretKey}"				# secret key (from portal or Sub Account)
        	secret_key = bytes(secret_key, 'UTF-8')
        
        	method = "GET"						# HTTPメソッド
        	uri = "/api/v2/channels?isPage=true"			# ドメインを除く「/」以下の全体 URL(クエリストリングを含む)
        
        	message = method + " " + uri + "\n" + timestamp + "\n"
        	+ access_key
        	message = bytes(message, 'UTF-8')
        	signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        	return signingKey
        Python
        <?php
        
        $access_key = "{accessKey}";
        $secret_key = "{secretKey}";
        $url = "/api/v2/channels";
        $timestamp = getMillisecond();
        
        $message = "GET";
        $message .= " ";
        $message .= $url;
        $message .= "\n";
        $message .= $timestamp;
        $message .= "\n";
        $message .= $access_key;
        
        $signature = base64_encode(hash_hmac('sha256', $message, $secret_key, true));
        
        $headers = array(
          "Content-Type: application/json;",
          "x-ncp-apigw-timestamp: ".$timestamp."",
          "x-ncp-iam-access-key: ".$access_key."",
          "x-ncp-apigw-signature-v2: ".$signature.""
        );
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://vodstation.apigw.ntruss.com".$url);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        
        echo $response;
        
        function getMillisecond()
        {
          list($microtime, $timestamp) = explode(' ', microtime());
          $time = $timestamp.substr($microtime, 2, 3);
          return $time;
        }
        
        ?>
        PHP
        function makeSignature() {
        	nl=$'\\n'
        
        	TIMESTAMP=$(echo $(($(date +%s%N)/1000000)))	# 現在のタイムスタンプ(epoch、millisecond)
        	ACCESSKEY="{accessKey}"				# access key id (from portal or Sub Account)
        	SECRETKEY="{secretKey}"				# secret key (from portal or Sub Account)
        	METHOD="GET"					# HTTPメソッド
        	URI="/api/v2/channels?isPage=true"		# ドメインを除く「/」以下の全体 URL(クエリストリングを含む)
        
        	SIG="$METHOD"' '"$URI"${nl}
        	SIG+="$TIMESTAMP"${nl}
        	SIG+="$ACCESSKEY"
        
        	SIGNATURE=$(echo -n -e "$SIG"|iconv -t utf8 |openssl dgst -sha256 -hmac $SECRETKEY -binary|openssl enc -base64)
        }
        Bash

        VOD Station APIのリクエスト構成

        Header
          x-ncp-region_code:{Region Code}
          x-ncp-apigw-timestamp:{Timestamp}
          x-ncp-iam-access-key:{Sub Account Access Key}
          x-ncp-apigw-signature-v2:{API Gateway Signature}
          Content-Type:application/json
        Body
          Json Object
        URL
          https://vodstation.apigw.ntruss.com/api/v2/{action}
        Plain text

        VOD Station APIのリクエストサンプル

        curl -i -s -X POST \
         -H "Content-Type:application/json" \
         -H "x-ncp-region_code:KR" \
         -H "x-ncp-apigw-timestamp:1521787414578" \
         -H "x-ncp-iam-access-key:6uxz1nKkcYwUjWRG5Q1V7NsW0i5jErlu2NjBXXgy" \
         -H "x-ncp-apigw-signature-v2:iJFK773KH0WwQ79PasqJ+ZGixtpDQ/abS57WGQdld2M=" \
         "https://vodstation.apigw.ntruss.com/api/v2/channles"\
         -d "{ \"cdn\": {\"profileId\": 1111, \"type\":\"GLOBAL_EDGE\", \"regionType\":\"KOREA\"}, \"createCdn\": true, \"name\": \"api-guide\", \"protocolList\": [ \"HLS\", \"DASH\" ], \"segmentDuration\": 5, \"storageBucketName\": \"guide\"}"
        Plain text

        VOD Station API Content-Type

        VOD Station API HTTP Requestと Response Bodyを通じて伝達されるすべてのデータの Content-typeはapplication/jsonを使用します。


        この記事は役に立ちましたか?

        Changing your password will log you out immediately. Use the new password to log back in.
        First name must have atleast 2 characters. Numbers and special characters are not allowed.
        Last name must have atleast 1 characters. Numbers and special characters are not allowed.
        Enter a valid email
        Enter a valid password
        Your profile has been successfully updated.