tapp/php-sdk-bands-in-town-api

Bands In Town API 的 PHP SDK

v2.0.0 2024-04-05 18:40 UTC

This package is auto-updated.

Last update: 2024-09-05 19:27:17 UTC


README

提供 Bands In Town 公共搜索 API 的 PHP 封装。

安装

通过 Composer 安装

composer require tapp/php-sdk-bands-in-town-api

使用方法

实例化 API 类

use BandsInTownApi\BandsInTownApi;

$bandsInTownApi = new BandsInTownApi;

公共 API

公共 API 文档
https://artists.bandsintown.com/support/public-api

$bandsInTownApi->api('public')

身份验证

$bandsInTownApi->withQueryAuth('app_id', 'your-app-id');

按名称获取艺术家信息

$bandsInTownApi->api('public')->artistInfoByName('artist name');

例如:

$artistInfoByName = $bandsInTownApi->api('public')->artistInfoByName('Justin Bieber');
$artistInfoByName->body();
// "{"id": "307871", "name": "Justin Bieber", "url": "https://www.bandsintown.com/a/307871?came_from=267&app_id=58c406aaf44bbb601a1bc5a75d0a4ca6", "mbid": "e0140a67-e4d1-4f13-8a01-364355bee46e", "options": {"display_listen_unit": false}, "tracking": [], "image_url": "https://photos.bandsintown.com/large/11112851.jpeg", "thumb_url": "https://photos.bandsintown.com/thumb/11112851.jpeg", "facebook_page_url": "https://#/67253243887", "tracker_count": 5295141, "upcoming_event_count": 0, "support_url": "", "links": [{"type": "itunes", "url": "https://itunes.apple.com/us/artist/justin-bieber/320569549"}, {"type": "youtube", "url": "https://www.youtube.com/user/kidrauhl"}, {"type": "amazon", "url": "https://music.amazon.com/artists/B002F0BWIM"}, {"type": "spotify", "url": "https://open.spotify.com/artist/1uNFoZAHBGtllmzznpCI3s"}, {"type": "snapchat", "url": "https://www.snapchat.com/add/rickthesizzler"}, {"type": "store/merch", "url": "https://shop.justinbiebermusic.com"}, {"type": "tumblr", "url": "https://justinbieber.tumblr.com"}, {"type": "newsletter", "url": "https://www.justinbiebermusic.com"}, {"type": "soundcloud", "url": "https://soundcloud.com/justinbieber"}, {"type": "facebook", "url": "https://#/JustinBieber/"}, {"type": "iheart", "url": "https://www.iheart.com/artist/justin-bieber-44368/"}, {"type": "instagram", "url": "https://www.instagram.com/justinbieber/"}, {"type": "website", "url": "https://www.justinbiebermusic.com/"}, {"type": "vevo", "url": "https://www.youtube.com/user/JustinBieberVEVO"}, {"type": "twitter", "url": "https://twitter.com/justinbieber"}], "artist_optin_show_phone_number": false, "show_multi_ticket": true}"

按 ID 获取艺术家信息

$bandsInTownApi->api('public')->artistInfoById('artist id');

例如:

$artistInfoById = $bandsInTownApi->api('public')->artistInfoById('307871');

按 Facebook 页面 ID 获取艺术家信息

$bandsInTownApi->api('public')->artistInfoByFacebookPageId('facebook page id');

例如:

$artistInfoById = $bandsInTownApi->api('public')->artistInfoByFacebookPageId('67253243887');

艺术家即将举行的活动

$bandsInTownApi->api('public')->artistUpcomingEvents('artist name');

例如:

$artistUpcomingEvents = $bandsInTownApi->api('public')->artistUpcomingEvents('Christina Aguilera');;

$artistUpcomingEvents->body();
// [{"id":"104054519","url":"https:\/\/www.bandsintown.com\/e\/104054519?app_id=58c406aaf44bbb601a1bc5a75d0a4ca6&came_from=267&utm_medium=api&utm_source=public_api&utm_campaign=event","datetime":"2023-05-06T15:00:00","title":"Lovers & Friends 2023","description":"","artist":{"id":"39","name":"Christina Aguilera","url":"https:\/\/www.bandsintown.com\/a\/39?came_from=267&app_id=58c406aaf44bbb601a1bc5a75d0a4ca6","mbid":"b202beb7-99bd-47e7-8b72-195c8d72ebdd","options":{"display_listen_unit":false},"tracking":[],"image_url":"https:\/\/photos.bandsintown.com\/large\/12754027.jpeg","thumb_url":"https:\/\/photos.bandsintown.com\/thumb\/12754027.jpeg","facebook_page_url":"http:\/\/www.facebook.com\/5565627823","tracker_count":2024835,"upcoming_event_count":1,"support_url":"","links":[{"type":"facebook","url":"https:\/\/www.facebook.com\/christinaaguilera\/"},{"type":"tiktok","url":"https:\/\/www.tiktok.com\/@xtina"},{"type":"linktree","url":"https:\/\/linktr.ee\/xtinauniverse"},{"type":"website","url":"https:\/\/www.christinaaguilera.com\/"},{"type":"youtube","url":"https:\/\/www.youtube.com\/christinaaguilera"},{"type":"twitter","url":"https:\/\/twitter.com\/XTINA"},{"type":"instagram","url":"https:\/\/www.instagram.com\/xtina\/"},{"type":"spotify","url":"https:\/\/open.spotify.com\/artist\/1l7ZsJRRS8wlW3WfJfPfNS"},{"type":"itunes","url":"https:\/\/music.apple.com\/artist\/christina-aguilera\/259398"},{"type":"soundcloud","url":"https:\/\/soundcloud.com\/christinaaguilera"}],"artist_optin_show_phone_number":false,"show_multi_ticket":true},"venue":{"location":"Las Vegas, NV","name":"Lovers & Friends 2023","latitude":"36.1431237","longitude":"-115.1621698","street_address":"311 W Sahara Ave","postal_code":"89101","city":"Las Vegas","country":"United States","region":"NV"},"lineup":["Christina Aguilera"],"offers":[{"type":"Tickets","url":"https:\/\/www.bandsintown.com\/t\/104054519?app_id=58c406aaf44bbb601a1bc5a75d0a4ca6&came_from=267&utm_medium=api&utm_source=public_api&utm_campaign=ticket","status":"available"}],"artist_id":"39","on_sale_datetime":"","festival_start_date":"2023-05-06","festival_end_date":"2023-05-06","festival_datetime_display_rule":"date","starts_at":"2023-05-06T15:00:00","ends_at":"2023-05-06T23:30:00","datetime_display_rule":"datetime","bandsintown_plus":false}]
$artistUpcomingEvents->status(); 
// 200

按日期范围获取艺术家活动

$bandsInTownApi->api('public')->artistEventsByDateRange('artist name');

例如:

$artistEventsByDateRange = $bandsInTownApi->api('public')->artistEventsByDateRange('Christina Aguilera', '2023-05-01,2023-06-01');

艺术家的过往活动

$bandsInTownApi->api('public')->artistPastEvents('artist name');

例如:

$artistPastEvents = $bandsInTownApi->api('public')->artistPastEvents('Christina Aguilera');

所有艺术家活动

$bandsInTownApi->api('public')->artistAllEvents('artist name');

例如:

$allArtistEvents = $bandsInTownApi->api('public')->artistAllEvents('Christina Aguilera');

搜索 API

搜索 API 文档:https://artists.bandsintown.com/support/partner-search-api/

$bandsInTownApi->api('search')

身份验证

$bandsInTownApi->withHeaderAuth('your-api-key');

可用方法

要搜索的实体数组

->entities([
    [
        'type' => 'artist',
        'order' => 'trackers',
        'limit' => 2,
        'offset' => 0,
    ],
])

搜索术语

->term('Bell')

搜索类型。可能的值:'streaming', 'physical', 'both'(默认)

->type('streaming')

搜索流派。可能的值:见https://artists.bandsintown.com/support/partner-search-api/#query_string_parameters

->genre('pop')

搜索流派。可能的值:见https://artists.bandsintown.com/support/partner-search-api/#query_string_parameters

->genres([
    'pop', 
    'jazz'
])

将搜索限制在提供的实体范围。可能的值:'artist', 'event', 'venue', 'event_id'

->scopes([
    'artist',
])

将搜索限制在提供的区域。对艺术家不适用

->region([
    'latitude' => 45.496112,
    'longitude' => -73.569315,
])

将搜索限制在日期范围内。仅适用于活动搜索

->period([
    'starts_at' => '2021-08-20T00:00:00Z',
    'ends_at' => '2021-08-23T00:00:00Z',
])

过滤搜索。可能的值:'on tour'(艺术家搜索时使用),"recommended","tracked artist"(当提供用户对象时使用)

->filter('on tour')

发送请求

->send()

示例

带有分页的单个实体(按艺术家进行分页搜索)

$artist = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'artist',
            'order' => 'trackers',
            'limit' => 2,
            'offset' => 0,
        ],
    ])
    ->term('Lady')
    ->scopes([
        'artist'
    ])
    ->send();

检索多个实体(按艺术家和活动进行分页搜索)

$artistAndEvent = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'artist',
            'order' => 'trackers',
            'limit' => 2,
            'offset' => 0,
        ],
        [
            'type' => 'event',
            'order' => 'rsvps',
            'limit' => 4,
        ]
    ])
    ->term('Lady')
    ->scopes([
        'artist',
        'event',
    ])
    ->send();

检索特定活动

$event = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ]
    ])
    ->term('102617588')
    ->scopes([
        'event_id',
    ])
    ->send();

按艺术家 ID 搜索活动

$event = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
            'order' => 'rsvps',
            'limit' => 4,
        ],
    ])
    ->term('22741')
    ->scopes([
        'artist_id',
    ])
    ->send();

按名称或 ID 搜索场馆

// search by venue name
$venue = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'venue',
        ],
    ])
    ->term('Bell Centre')
    ->scopes([
        'venue',
    ])
    ->send();
// search by venue id
$venue = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'venue',
        ],
    ])
    ->term('10003087')
    ->scopes([
        'venue_id',
    ])
    ->send();

按场馆 ID 搜索活动

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ],
    ])
    ->term('10003087')
    ->scopes([
        'venue_id'
    ])
    ->send();

按场馆 ID 和流派搜索在该场馆演出过的艺术家和活动

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ],
    ])
    ->term('10003087')
    ->genre('pop')
    ->send();

按 GPS 坐标和流派搜索活动

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ],
    ])
    ->region([
        'latitude' => 45.496112,
        'longitude' => -73.569315,
    ])
    ->genre('pop')
    ->send();

搜索直播活动

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ],
    ])
    ->term('jason wild')
    ->type('streaming')
    ->send();

按流派搜索直播活动

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
        ],
    ])
    ->genre('latin')
    ->type('streaming')
    ->send();

搜索最近修改过的一段时间内的实体活动,按开始日期排序

$events = $bandsInTownApi->api('search')
    ->entities([
        [
            'type' => 'event',
            'order' => 'start_date',
            'limit' => 199,
            'offset' => 0,
        ],
    ])
    ->term('2021-08-20T00:00:00ZTO2021-08-23T00:00:00Z')
    ->scopes(['last_modified_date'])
    ->type('physical')
    ->send();

测试

./vendor/bin/pest

更新日志

请参阅更新日志以获取有关最近更改的更多信息。

贡献

欢迎贡献! :)

许可

MIT 许可证(MIT)。有关更多信息,请参阅许可证