17372


[Mashup Awards
10向け提供APIガイド](http://search.nicovideo.jp/docs/api/contest.html)を使用したWebアプリケーションを開発しています。

`XMLHttpRequest`を使用して、生放送をjsonで取得することは出来たのですが、取得できた内容にコミュニティid（`co****`）が存在しません。

[code]

    # 例
    $ curl -X POST -d '{"issuer":"test","reason":"ma10","query":"初音ミク","from":0,"size":100,"service":["live"],"search":["title","body","caption","tags"],"join":["cmsid","title","description","thumbnail_url","start_time","update_time","last_comment_time","view_counter","comment_counter","mylist_counter","tags","channel_id","main_community_id","length_seconds","score_timeshift_reserved","provider_type","channel_id","live_status","member_only","is_official","serial_status","episode_count","is_sample","genre","author","publisher","label","is_free","price","series_id","series_number","series","charticle_ppv_type","is_member_only","thumbnail_key","media_id","media_name"],"filters":[],"order":"desc","sort_by":"start_time","timeout":10000}' http://api.search.nicovideo.jp/api/
    
[/code]

なお、返ってくる`lv***`の番号とは関連性が無いようでした。

`http://live.nicovideo.jp/watch/lv***`を、代理サーバーでスクレピングし、中の`<img>`からURLを抽出してブラウザへ返す方法を試しましたが、こちらはアクセス制限が厳しく、１秒間隔でアクセスしても拒否されました。

ログインセッションキーを代理サーバーへ渡し、[getplayerstatus](http://live.nicovideo.jp/api/getplayerstatus/nsen/hotaru)を代理サーバーから取得して、ブラウザへ返す方法を考えましたが、これはWEBアプリケーションとして操作難易度が高いので、最終手段にしたいです。

> 参考：  
>  [ニコニコ動画検索APIのリクエスト発行テスト jsdo.it/59naga](http://jsdo.it/59naga/niconico-api-
> test)（[Internet
> Archive](https://web.archive.org/web/20191017111206/http://jsdo.it/59naga/niconico-
> api-test)）


CC BY-SA 4.0
2015-10-07T09:52:13.390
17360
2019-10-17T11:13:16.973
2019-10-17T11:13:16.973
19110
9834
question
javascript angularjs
ニコニコ生放送のコミュニティidをログインせずに取得したい


[Vita
API](http://www59.atwiki.jp/nicoapi/pages/24.html)というものから、ログイン不要で取得が可能でした。

[code]

    $ curl http://api.ce.nicovideo.jp/liveapi/v1/video.array?__format=json&v=lv237697178
    # {"nicolive_video_response":{"video_info":{"video":{"id":"lv237697178","title":"\uff12\uff14\u6642\u9593\u653e\u9001 \uff08MIKUMAX)","open_time":"2015-10-07 13:26:49","start_time":"2015-10-07 13:26:52","schedule_end_time":"","end_time":"2015-10-07 13:56:52","provider_type":"community","related_channel_id":"","hidescore_online":"0","hidescore_comment":"0","community_only":"1","channel_only":"0","view_counter":"3","comment_count":"0","_ts_reserved_count":"0","timeshift_enabled":"0","is_hq":"0"},"community":{"id":"1240226","name":"\uff12\uff14\u6642\u9593\u653e\u9001\u3000\u521d\u97f3\u30df\u30af\uff08MIKUMAX)","channel_id":"","global_id":"co1240226","thumbnail":"http:\/\/icon.nimg.jp\/community\/124\/co1240226.jpg?1440712338","thumbnail_small":"http:\/\/icon.nimg.jp\/community\/s\/124\/co1240226.jpg?1440712338"}},"count":"1","@status":"ok"}}
    
[/code]


CC BY-SA 3.0
2015-10-07T10:08:06.887
17362
2015-10-07T10:08:06.887
9834
17360
answer


そのAPIでレスポンスに含まれる項目を制御するのは `join`
というパラメータですが、質問にも書かれている[APIガイド](http://search.nicovideo.jp/docs/api/contest.html)で生放送の検索クエリ例を見ると、次のように書かれています。

[code]

    ...
      "join":[
        "cmsid",
        "title",
        "description",
        "community_id",
        "community_icon",
        "open_time",
        "start_time",
        "end_time",
        "score_timeshift_reserved",
        "provider_type",
        "channel_id",
        "live_status",
        "member_only"
      ],
    ...
    
[/code]

`community_id` というのがありますね。

[code]

    $.ajax({
      type: 'post',
      url: 'http://api.search.nicovideo.jp/api/',
      data: JSON.stringify({
        query: "初音ミク",
        service: ["live"],
        search: ["tags"],
        join: ["cmsid", "title", "community_id"],
        filters: [{type: "equal", field: "provider_type", value: "community"}],
        size: 3,
        issuer: "stackoverflow_sample",
        reason: "ma10"
      }),
      contentType: 'application/json',
      dataType: 'text',
      success: function(resp) {
        $.each(resp.split('\n'), function (_, chunk) {
          if (chunk && (json = JSON.parse(chunk)) &&json.type === 'hits') {
            $('pre').text(JSON.stringify(json.values, null, '    '));
          }
        })
      }
    });
[/code]

[code]

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
    <pre class="prettyprint"></pre>
[/code]


CC BY-SA 3.0
2015-10-07T12:04:11.823
17372
2015-10-07T12:14:05.930
2015-10-07T12:14:05.930
8000
8000
17360
answer