我正在尝试使用 Spotify Web API 构建一个 Spotify 网络播放器。我在 Spotify 上注册了我的应用程序并将回调 URL 列入白名单。然后授权过程工作正常。我收到用于提出其他请求的令牌。但是当我尝试提出一个简单的当前播放请求时
https://developer.spotify.com/web-api/get-the-users-currently-playing-track/
我收到
Array ( [error] => Array ( [status] => 401 [message] => Permissions missing ) )
Run Code Online (Sandbox Code Playgroud)
PHP代码是:
session_start();
$req = $_SESSION['token_type'] . " " . $_SESSION['token'];
$headers_after_token = array(
"Accept: */*",
"Authorization: " . $req);
$url="https://api.spotify.com/v1/me/player/currently-playing";
echo "<br>REQ-currently-playing: ".$req."<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_after_token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
echo "<br><br>";
print_r($response);
Run Code Online (Sandbox Code Playgroud)
在$_SESSION['token_type']
作为API端点引用提到包含“承载”
https://developer.spotify.com/web-api/endpoint-reference/
在$_SESSION['token'] …
我的问题是:是否可以在 WebAPI Spotify(特别是 Spotipy)中同时使用两个或多个范围?例如使用范围“user-modify-playback-state”和“user-library-read”
谢谢
我想在我的 Flutter 应用程序中设置 Spotify API 的 oAuth 身份验证。我选择了 flutter_web_auth 0.1.1 包。到目前为止,我已经设法让用户可以登录到 Spotify。登录后,用户应该被重定向回我的应用程序。那行不通。Spotify 总是将用户重定向到另一个网站,而不是返回到应用程序。用户登录后如何关闭 WebView 并将用户重定向到我的应用程序?
import 'package:flutter/material.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
authenticate();
}
void authenticate() async {
// Present the dialog to the user
final result = await FlutterWebAuth.authenticate(
url:
"https://accounts.spotify.com/de/authorize?client_id=78ca499b2577406ba7c364d1682b4a6c&response_type=code&redirect_uri=https://partyai/callback&scope=user-read-private%20user-read-email&state=34fFs29kd09",
callbackUrlScheme: "https://partyai/callback",
);
// Extract token from resulting url
final token = Uri.parse(result).queryParameters['token'];
print('token');
print(token);
} …
Run Code Online (Sandbox Code Playgroud) 我想编写一个访问 Spotify Android SDK 的包。我正在尝试添加身份验证。那是行不通的。我没能打开登录屏幕。我是否需要在 dart 代码中添加视图(如下所述: https: //60devs.com/how-to-add-native-code-to-flutter-app-using-platform-views-android.html) ?
镖:
...
void initPlatformState() async {
try {
String test = await Nativecode05.spotifyTest;
print(test);
} on PlatformException {
platformVersion = 'Failed';
}
}
...
Run Code Online (Sandbox Code Playgroud)
包裹:
import 'dart:async';
import 'package:flutter/services.dart';
class Nativecode05 {
static const MethodChannel _channel = const MethodChannel('nativecode05');
static Future<String> get spotifyTest async {
final String version = await _channel.invokeMethod('spotifyTest');
return version;
}
}
Run Code Online (Sandbox Code Playgroud)
包中的Java代码:
package example.com.nativecode05;
import io.flutter.Log;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import …
Run Code Online (Sandbox Code Playgroud) 我需要根据歌曲名称和艺术家姓名为用户检索一首歌曲(这样我就得到了正确的歌曲)。最终目标是获取轨道 id。这是我认为可行的代码:
searchResults = spotifyObject.search(q="artist:" + artist + "track:" + searchQuery, type="track")
Run Code Online (Sandbox Code Playgroud)
其中,artist 是艺术家/乐队的名称,searchQuery 是曲目的名称。这应该返回特定轨道的 JSON 块,但返回:
{
"tracks": {
"href": "https://api.spotify.com/v1/search?query=artist%3AHarry+Stylestrack%3AWatermelon+Sugar&type=track&offset=0&limit=10",
"items": [],
"limit": 10,
"next": null,
"offset": 0,
"previous": null,
"total": 0
}
Run Code Online (Sandbox Code Playgroud)
}
我想使用命令行从 Spotify API 检索信息,例如如下所示:
curl "https://api.spotify.com/v1/search?type=artist&q=<someartist>"
Run Code Online (Sandbox Code Playgroud)
但当我这样做时,我得到:
{
"error": {
"status": 401,
"message": "No token provided"
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的 Spotify 开发者帐户中创建了一个应用程序。有人可以引导我完成如何传递我的凭据和搜索请求的过程吗?我不想编写应用程序或任何东西。我只想从命令行检索信息。
希望有人可以帮忙!
我正在制作自己的智能链接页面:
https://www.hooklust.com/oo.a/
Run Code Online (Sandbox Code Playgroud)
(仅完成一部分 - 忽略可怕的造型)
并且可以获取 Spotify 链接(顶部绿色按钮)以在 Spotify 网络应用程序中打开歌曲,但是这样的服务如何......
https://songwhip.com/hooklust/sekai-heiwa-world-peace
Run Code Online (Sandbox Code Playgroud)
点击 Spotify 链接后能否提示打开 Spotify 应用程序?当我单击他们的应用程序时,我看到“打开 Spotify - https://songwhip.com想要打开此应用程序”。迅速的。
谢谢
我想用Spotify API开发一个应用程序.我已经下载了适用于Windows的Spotify库,还为环境变量设置了路径spotify.dll
.我正在尝试运行Spotify开发者网站上提供的简单"hello word"示例,但我收到了Spotify函数的错误
getSpotifyApi(1);
我不知道这个功能到底是做什么的.
是否需要API_key
输入代码文件?我现在没有appkey.c
Spotify库中的文件.是API_key
和appkey.c
运行简单应用程序所需的文件?运行简单示例还有其他要求吗?
我想在 16x2 LCD 上显示 Spotify 中当前播放的歌曲。我正在考虑将 LCD 与我的 Arduino 连接,然后制作一个 Python 脚本,将 Spotify 当前播放的歌曲发送到 Arduino。
为了切入正题,我正在寻找一种在 Python 中获取 Spotify 当前播放歌曲的方法。(我使用的是 Windows 8。)我找到了一些类似 dbus 的方法,但它们要么适用于 Linux,要么适用于 Mac。
提前致谢!(抱歉英语语法不好。)
为了在我的Web应用程序中获取Spotify API的访问令牌(由他们的Web授权流程指定),我了解到我必须提出POST
请求.但是,当我这样做时,我得到了XMLHttpRequest
500 Error
由于跨源问题.
我已经想出了如何允许CORS GET
请求,但我不知道如何对POST
请求执行相同的操作.此链接提供配置提示,但它保留实际路由GET
和POST
空白.
这是我的Express.js服务器的相关代码:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(express.static(__dirname + '/public')); // looks in public directory, not root directory (protects files)
app.get('/', function(req, res) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.send(__dirname + '\\index.html')
});
app.post('/', function(req, res) {
res.send(req.body.spotify);
});
Run Code Online (Sandbox Code Playgroud)
(spotify
是spotify-web-api-js
节点模块).
我以前曾尝试将确切的代码复制app.get
到app.post
,但这导致服务器崩溃.
这是我程序的JavaScript文件中的一些代码,它打算POST
在用户单击一个按钮后发送请求,该按钮将它们带到Spotify的授权路径的开头并批准登录:
$('#spotify').on('click', …
Run Code Online (Sandbox Code Playgroud) 所以我试图弄清楚如何从我创建的播放列表中获取 playlist_id ,但即使在阅读了不稳定的文档后,我也没有找到使用哪种方法。
import spotipy
import json
import sys
from spotipy.oauth2 import SpotifyOAuth
import requests
import os
import dotenv
from json.decoder import JSONDecodeError
SPOTIPY_CLIENT_ID="secret"
SPOTIPY_CLIENT_SECRET="secret"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope="playlist-modify-private",
client_id=SPOTIPY_CLIENT_ID,
client_secret=SPOTIPY_CLIENT_SECRET,
redirect_uri="https://google.com",
cache_path="token.txt"))
user_id = sp.current_user()["id"] # grabs user name
sp.user_playlist_create(user_id,"Funky Music",public=False,collaborative=False, description="Test")
Run Code Online (Sandbox Code Playgroud)
这就是我对代码的了解程度。
所以我想使用 Spotify 的 Web API。我已阅读一些文档,您需要使用 PKCE 实现身份验证代码。我不是 100% 确定如何做到这一点,并且可以使用一些帮助。
authentication android restful-authentication spotify kotlin