Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

埋め込みプレイヤーに対応させたい #9

Open
ot0m1 opened this issue Sep 3, 2019 · 4 comments
Open

埋め込みプレイヤーに対応させたい #9

ot0m1 opened this issue Sep 3, 2019 · 4 comments

Comments

@ot0m1
Copy link
Collaborator

ot0m1 commented Sep 3, 2019

https://developer.spotify.com/documentation/widgets/generate/play-button/

ここらへん参照かな〜

@ot0m1
Copy link
Collaborator Author

ot0m1 commented Sep 4, 2019

埋め込みプレイヤーはiframeで以下のコードで利用できる模様。

<iframe src="https://open.spotify.com/embed/album/1DFixLWuPkv3KT3TnV35m3" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>

@ot0m1
Copy link
Collaborator Author

ot0m1 commented Sep 4, 2019

確認したら上記コードのid部分1DFixLWuPkv3KT3TnV35m3を可変にすれば自由にアルバム取れる。

idはspotifyのapiから返ってくる情報のうち、以下のhashに格納されている。

{"external_urls"=>
  {"spotify"=>"https://open.spotify.com/artist/2KEDbpUlz9nwtGywHT4gyf"},
 "href"=>"https://api.spotify.com/v1/artists/2KEDbpUlz9nwtGywHT4gyf",
 "id"=>"2KEDbpUlz9nwtGywHT4gyf",
 "name"=>"Los Secretos",
 "type"=>"artist",
 "uri"=>"spotify:artist:2KEDbpUlz9nwtGywHT4gyf"}

@ot0m1
Copy link
Collaborator Author

ot0m1 commented Sep 4, 2019

僕のコードだと@album["artists"]で取れる。

railsのerbをこんな感じで作れば埋め込めそう。

<iframe src="https://open.spotify.com/embed/album/<%= @album["id"] %>" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>

@ot0m1
Copy link
Collaborator Author

ot0m1 commented Sep 4, 2019

railsはiframeもセキュリティに引っかかるっぽいので、別途バリデーションを調整する必要がある。

https://qiita.com/keisuke_kimura/items/1a0812837baab2cc100a

response.headers['X-Frame-Options'] = 'ALLOW-FROM https://open.spotify.com'

でいけるのかな〜。帰って確認してみよ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant