0

ユーザーがバンド名 (「Rad」など) の入力を開始し、Discogs API がそれらに最も類似した 10 個の提案 (「Radical Face」など) を表示できるようにする Web サイトを作成しています。 、「レディオヘッド」など)。これらの提案は、アルファベット順または理想的には人気順に並べ替えることができます。

問題は、Discogs API に対してそのようなリクエストを行う方法がわからないことです。これは、 http://api.discogs.com/releases/1のコンテンツを取得して解析するコードです。

任意の洞察をいただければ幸いです。ありがとうございました。

    <?php
        $url = "http://api.discogs.com/releases/1"; // add the resource info to the url. Ex. releases/1

        //initialize the session
        $ch = curl_init();

        //Set the User-Agent Identifier
        curl_setopt($ch, CURLOPT_USERAGENT, 'SiteName/0.1 +http://your-site-here.com');

        //Set the URL of the page or file to download.
        curl_setopt($ch, CURLOPT_URL, $url);

        //Ask cURL to return the contents in a variable instead of simply echoing them
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        //Execute the curl session
        $output = curl_exec($ch);

        //close the session
        curl_close ($ch);



        function textParser($text, $css_block_name){

            $end_pattern = '], "';

            switch($css_block_name){
                # Add your pattern here to grab any specific block of text
                case 'description';
                    $end_pattern = '", "';
                    break;
            }

            # Name of the block to find
            $needle = "\"{$css_block_name}\":";

            # Find start position to grab text
            $start_position = stripos($text, $needle) + strlen($needle);

            $text_portion = substr($text, $start_position, stripos($text, $end_pattern, $start_position) - $start_position + 1);
            $text_portion = str_ireplace("[", "", $text_portion);
            $text_portion = str_ireplace("]", "", $text_portion);

            return $text_portion;
        }

        $blockStyle = textParser($output, 'styles');
        echo $blockStyle. '<br/>';

        $blockDescription = textParser($output, 'description');
        echo $blockDescription. '<br/>';



    ?> 
4

1 に答える 1

0

discogs API を使用すると、簡単に検索を実行できます。すでにドキュメントをご覧になっていると思います: https://www.discogs.com/developers/#page:database,header:database-search

そこでは、アーティストのみを検索したいとさえ言えます。結果を取得するときは、自分でアルファベット順に並べ替えるか、結果の順序に従って中継する必要があります。ドキュメンテーションを見る限り、注文はdiscogsですでに何らかの人気があると思います。また、Web サイト統合検索と同じ実装です。

結果セットは非常に大きくなる可能性があることに注意してください。したがって、すべての結果ページを取得する必要があるため、アルファベット順で並べ替えるのは最善の方法ではありません。ここでは、page_sizeパラメーターをページあたり最大 100 項目まで増やす必要があります。

于 2016-05-12T09:17:12.487 に答える