标签: spotify

如何使用Python播放Spotify音频?

我想知道是否可以播放Spotify with Python(如果可能的话2.7版)的歌曲以及如何播放.

python spotify python-2.7

12
推荐指数
1
解决办法
2万
查看次数

从Spotify意图开始一首歌

无论如何从它的URI启动Spotify Track?

我尝试了以下方法,但没有一个工作.当Spotify打开时,它总是落在播放列表页面中,而不是轨道播放器.

String spotifyTrackURI = "spotify:track:1cC9YJ8sQjC0T5H1fXMUT2";
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.spotify.mobile.android.ui");

// I've tried with Intent#putExtra()..
launchIntent.putExtra( SearchManager.QUERY, spotifyTrackURI );
// or with setData
launchIntent.setData(Uri.parse(spotifyTrackURI))

context.startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)

谢谢

android spotify android-intent

11
推荐指数
1
解决办法
1万
查看次数

怎么可能知道Spotify正在从外部Android应用程序播放?

我刚刚在Spotify for Android设置屏幕中找到了此设置选项:

"设备广播状态 - 允许您设备上的其他应用看到您正在收听的信息"

我猜这意味着任何其他应用都可以通过Spotify访问正在播放的内容.如何实施?周围有文件吗?

谢谢

android spotify

11
推荐指数
2
解决办法
9533
查看次数

如何使用Spring Security 5和OAuth2客户端获取刷新令牌并进行API调用?

我目前正在使用 Spring Security + OAUth2 协议构建 Spring Boot 应用程序。

这是我正在关注的 Spotify 授权指南

我无法理解如何执行授权代码流程的步骤 2 - 4。我能够获得授权并获得授权代码来交换访问和刷新令牌,但我不确定如何获取令牌,然后开始进行 API 调用。

阅读 Spring 文档让我对某些事情感到困惑。

  1. 我如何获得令牌?我注意到登录后它存储在重定向的 URL 中,我是使用查询参数获取它还是存储在 OAuth2ClientService 对象中?
  2. 授权指南指出我必须对令牌端点进行 POST 调用才能获取刷新和访问令牌。我假设我没有使用 WebClient/RestTemplate 执行此操作,因为我能够使用应用程序属性执行 GET 登录请求。如果是这样我该如何实现这个目标?
  3. 我如何使用这些令牌来访问 API 数据?通常,如果不需要令牌,我会使用 WebClient 进行 REST API 调用。如果我获得令牌,我会按照通常的方式进行操作,但使用访问令牌作为查询。

这是我的 application.properties

#
# OAuth ClientRegistration Properties
#
spring.security.oauth2.client.registration.spotify.client-id=#
spring.security.oauth2.client.registration.spotify.client-secret=#
spring.security.oauth2.client.registration.spotify.provider=spotify-provider
spring.security.oauth2.client.registration.spotify.client-authentication-method=basic
spring.security.oauth2.client.registration.spotify.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.spotify.redirect-uri=http://localhost:8080/redirect
spring.security.oauth2.client.registration.spotify.scope=user-read-private,user-read-email

#
# OAuth ProviderDetails Properties
#
spring.security.oauth2.client.provider.spotify-provider.authorization-            
uri=https://accounts.spotify.com/authorize?show_dialog=true

spring.security.oauth2.client.provider.spotify-provider.token-  
uri=https://accounts.spotify.com/api/token

spring.security.oauth2.client.provider.spotify-provider.user-info-uri=https://api.spotify.com/v1/me
spring.security.oauth2.client.provider.spotify-provider.user-name-attribute=id
Run Code Online (Sandbox Code Playgroud)

这是我的 WebSecurityConfig

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected …
Run Code Online (Sandbox Code Playgroud)

spring-security spotify oauth-2.0 spring-boot spring-security-oauth2

11
推荐指数
1
解决办法
1万
查看次数

Spotify API:INVALID_APP_ID

我目前正在开发一个实现Spotify API的Android应用程序.我已经将所有代码连接到我的应用程序以使用教程进行spotify,并且已经在我的应用程序上工作了一段时间.当我在验证用户身份后通过我的应用程序播放歌曲时,它可以很好地工作,就在我的模拟器上.当我将它切换到我的手机时,它无法正常工作,并在android响应中给了我一个INVALID_APP_ID错误.当我卸载Spotify关闭我的手机,然后尝试登录通过我的应用程序spotify,然后我能够从我的手机播放音乐没有任何崩溃.所以我的问题是如何解决这个问题?这是我验证用户的代码:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);

        // Check if result comes from the correct activity
        if (requestCode == requestcode) {
            AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
            if (response.getType() == AuthenticationResponse.Type.TOKEN) {
                Config playerConfig = new Config(this, response.getAccessToken(), client_id);
                token = response.getAccessToken();
                Spotify.getPlayer(playerConfig, this, new Player.InitializationObserver() {
                    @Override
                    public void onInitialized(Player player) {
                        mPlayer = player;
                        mPlayer.addConnectionStateCallback(.this);
                        mPlayer.addPlayerNotificationCallback(.this);

                    }

                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage()); …
Run Code Online (Sandbox Code Playgroud)

android spotify libspotify

10
推荐指数
1
解决办法
2590
查看次数

从Spotify应用程序获取数据(Windows/Mac)

如何从应用程序(Windows/Mac)获取音乐播放,倾斜,艺术家等数据.有一个使用Web API的选项,但我测试了Musixmatch应用程序,即使我离线也可以工作,因此可以某种方式连接到应用程序.

spotify spotify-app

10
推荐指数
2
解决办法
580
查看次数

如何在Spotify播放器中向前或向后10秒

我试图在Spotify播放器中添加(向前移动)10秒的歌曲持续时间或减去(向后移动)10秒,但是我真的很困惑如何添加或减去。

当我尝试使用此代码时,歌曲的持续时间不会改变

// forward button action 
@IBAction func moveFrdBtnAction(_ sender: Any) {
  SpotifyManager.shared.audioStreaming(SpotifyManager.shared.player, didSeekToPosition: TimeInterval(10))
}

// spotify delegate method seekToPosition
func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didSeekToPosition position: TimeInterval) {
    player?.seek(to: position, callback: { (error) in
        let songDuration = audioStreaming.metadata.currentTrack?.duration as Any as! Double
        self.delegate?.getSongTime(timeCount: Int(songDuration)+1)
    })
}
Run Code Online (Sandbox Code Playgroud)

我们正在两个平台(Android和iOS)上使用相同的SDK制作音乐应用程序,Spotify SDK的seekToPosition方法在Android版本中正常运行,但是在iOS版本中不起作用。委托方法调用本身,但音乐停止了。

您能否告诉我们为什么会发生这种情况,以及我们应该怎么做才能在iOS设备上运行它。

有人可以向我解释如何解决这个问题,我已经尝试解决这个问题,但没有结果。

任何帮助将不胜感激。

提前致谢。

duration spotify ios swift

10
推荐指数
1
解决办法
482
查看次数

PYTHON:requests.post() 如何发送编码为 application/x-www-form-urlencoded 的 request_body

我正在使用 Spotify API 开发一个应用程序。我的问题是我正在尝试获取access_token但它不起作用。在文档中,它说我需要发送编码为 application/x-www-form-urlencoded 的正文,所以我搜索了一下,它应该只需设置request_body为字典即可工作。

这是我的函数的代码:

    def get_access_token(self):
        auth_code, code_verifier = self.get_auth_code()
        endpoint = "https://accounts.spotify.com/api/token"

        # as docs said data should be encoded as application/x-www-form-urlencoded
        # as internet says i just need to send it as a dictionary. However it's not working
        request_body = {
                "client_id": f"{self.client_ID}",
                "grant_type": "authorization_code",
                "code": f"{auth_code}",
                "redirect_uri": f"{self.redirect_uri}",
                "code_verifier": f"{code_verifier}"
        }

        response = requests.post(endpoint, data=request_body)
        print(response)
Run Code Online (Sandbox Code Playgroud)

我得到的回应始终是<Response [400]> 这里是文档,步骤 4 https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for- code-exchange-pkce 注意:我尝试将其作为curl执行,它工作正常,我不确定我在python代码中做错了什么,命令如下:

curl -d client_id={self.client_ID} -d grant_type=authorization_code -d …
Run Code Online (Sandbox Code Playgroud)

python post spotify python-requests x-www-form-urlencoded

10
推荐指数
1
解决办法
2万
查看次数

如何使用 Spotify 的 PKCE 实施授权码

编辑:澄清一下,获取授权代码按预期工作。这纯粹是用授权码交换令牌的步骤失败了。

我正在尝试使用 PKCE 流程实现授权代码,以便使用 Spotify API 进行身份验证。我知道有一些库可以实现这一点,但我真的想自己实现它。我所说的流程是这样的: https: //developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce 我我能够制作链接以将用户重定向到同意页面并获取授权代码。但是,当我尝试将此代码交换为令牌时,我收到一个 400 错误请求,其中包含消息“无效的 client_secret”。这让我相信 Spotify 假设我正在尝试使用常规授权代码流程,因为客户端密钥根本不是 PKCE 流程的一部分。我怀疑我对 code_verifier 或 code_challenge 的编码错误。我在 SO(How tocalculate PCKE's code_verifier?)上找到了这个答案,并将其翻译为 C#,为 Base64 编码的哈希产生相同的结果,但它仍然不起作用。

下面是我生成 code_verifier 和 code_challenge 的代码,以及发出交换代码请求的代码。

代码验证器:

private string GenerateNonce()
{
    const string chars = "abcdefghijklmnopqrstuvwxyz123456789";
    var random = new Random();
    var nonce = new char[100];
    for (int i = 0; i < nonce.Length; i++)
    {
        nonce[i] = chars[random.Next(chars.Length)];
    }
    return new string(nonce);
}
Run Code Online (Sandbox Code Playgroud)

代码挑战:

    private string GenerateCodeChallenge(string codeVerifier)
    {
        using …
Run Code Online (Sandbox Code Playgroud)

c# oauth spotify oauth-2.0

10
推荐指数
2
解决办法
1万
查看次数

Spotify如何通过Gmail收件箱视图打开桌面应用程序?

Gmail中

这是我第一次看到这样的按钮(见右侧).单击该按钮可启动Spotify.Spotify如何为他们的电子邮件做到这一点?现在可以用其他应用程序完成吗?

gmail spotify

9
推荐指数
1
解决办法
1607
查看次数