SpotifyWebAPI\SpotifyWebAPI::deleteUserPlaylistTracks PHP Метод

deleteUserPlaylistTracks() публичный Метод

Requires a valid access token. https://developer.spotify.com/web-api/remove-tracks-playlist/
public deleteUserPlaylistTracks ( string $userId, string $playlistId, array $tracks, string $snapshotId = '' ) : string | boolean
$userId string ID of the user who owns the playlist.
$playlistId string ID of the playlist to delete tracks from.
$tracks array Array of arrays with tracks to delete. - id string Required. Spotify track ID. - positions int|array Optional. The track's position(s) in the playlist.
$snapshotId string Optional. The playlist's snapshot ID.
Результат string | boolean A new snapshot ID or false if the tracks weren't successfully deleted.
    public function deleteUserPlaylistTracks($userId, $playlistId, $tracks, $snapshotId = '')
    {
        $options = [];
        if ($snapshotId) {
            $options['snapshot_id'] = $snapshotId;
        }
        $options['tracks'] = [];
        for ($i = 0; $i < count($tracks); $i++) {
            $track = [];
            if (isset($tracks[$i]['positions'])) {
                $track['positions'] = (array) $tracks[$i]['positions'];
            }
            $track['uri'] = $this->idToUri($tracks[$i]['id']);
            $options['tracks'][] = $track;
        }
        $options = json_encode($options);
        $headers = $this->authHeaders();
        $headers['Content-Type'] = 'application/json';
        $uri = '/v1/users/' . $userId . '/playlists/' . $playlistId . '/tracks';
        $this->lastResponse = $this->request->api('DELETE', $uri, $options, $headers);
        $body = $this->lastResponse['body'];
        if (isset($body->snapshot_id)) {
            return $body->snapshot_id;
        }
        return false;
    }