PHP code example of 128na / niconico-rest-client

1. Go to this page and download the library: Download 128na/niconico-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

128na / niconico-rest-client example snippets


use NicoNicoRestClient\ClientFactory;
use NicoNicoRestClient\ApiSnapshot\Query;

$client = ClientFactory::create();

$query = new Query(['q'=> 'test']);
$result = $client->apiSnapshotSearch($query);
echo $result->statusOk() ? 'ok' : 'fail';

$videos = $result->getVideos();

foreach($videos as $video) {
    echo $video->getTitle() . PHP_EOL;
}

// クエリパラメーターを直接指定可能
$query = new Query(['q'=> 'test']);
// setメソッドでの設定も可能
$quert->setLimit(10);

$result = $client->apiSnapshotSearch($query);
echo $result->statusOk() ? 'ok' : 'fail';

$videos = $result->getVideos();

foreach($videos as $video) {
    echo $video->getTitle() . PHP_EOL;
}

https://api.ce.nicovideo.jp/api/v1/user.info?__format=json&user_id=2
https://api.ce.nicovideo.jp/nicoapi/v1/video.info?__format=json&v=***
https://api.ce.nicovideo.jp/nicoapi/v1/video.array?__format=json&v=***,***
https://api.ce.nicovideo.jp/nicoapi/v1/mylistgroup.get?__format=json&group_id=***
https://api.ce.nicovideo.jp/nicoapi/v1/mylist.list?__format=json&group_id=***&limit=50&from=0
https://api.ce.nicovideo.jp/nicoapi/v1/user.myvideo?__format=json&user_id=***

https://www.nicovideo.jp/user/***/video?rss=atom
https://www.nicovideo.jp/user/***/mylist/***?rss=atom