将 Void 函数分配给 Auth 事件时出现编译错误
Compile Error While Assigning Void Function to Auth Event
我正在构建一个需要 Spotify 使用 ImplicitGrantAuth
对用户进行身份验证的应用程序。我已经在 Spotify 的 dev 上设置了我的应用程序并且有一个 ClientID
。我正在为此应用程序使用 JohnnyCrazy/SpotifyAPI-NET
。
代码片段:
static ImplicitGrantAuth auth;
static void Main(string[] args)
{
//Create the auth object
auth = new ImplicitGrantAuth()
{
//Your client Id
ClientId = "XXXXXXXXXXXXXXXXXX", // example only
//Set this to localhost if you want to use the built-in HTTP Server
RedirectUri = "http://localhost",
//How many permissions we need?
Scope = Scope.UserReadPrivate,
};
//Start the internal http server
auth.StartHttpServer();
//When we got our response
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent; // <-- Error here!
//Start
auth.DoAuth();
}
static void auth_OnResponseReceivedEvent(Token token, string state, string error)
{
//stop the http server
auth.StopHttpServer();
var spotify = new SpotifyWebAPI()
{
TokenType = token.TokenType,
AccessToken = token.AccessToken
};
//We can now make calls with the token object
}
编译错误:
No overload for 'auth_OnResponseReceivedEvent' matches delegate 'SpotifyAPI.Web.Auth.ImplicitGrantAuth.OnResponseReceived'
我不确定我是否忽略了一些非常简单的东西,或者我是否需要特别添加一些东西。我对使用事件处理程序也很陌生。
您的 auth_OnResponseReceivedEvent
方法中的参数过多。 OnResponseReceived
委托中没有string state
参数:
public delegate void OnResponseReceived(Token token, String error);
public event OnResponseReceived OnResponseReceivedEvent;
我正在构建一个需要 Spotify 使用 ImplicitGrantAuth
对用户进行身份验证的应用程序。我已经在 Spotify 的 dev 上设置了我的应用程序并且有一个 ClientID
。我正在为此应用程序使用 JohnnyCrazy/SpotifyAPI-NET
。
代码片段:
static ImplicitGrantAuth auth;
static void Main(string[] args)
{
//Create the auth object
auth = new ImplicitGrantAuth()
{
//Your client Id
ClientId = "XXXXXXXXXXXXXXXXXX", // example only
//Set this to localhost if you want to use the built-in HTTP Server
RedirectUri = "http://localhost",
//How many permissions we need?
Scope = Scope.UserReadPrivate,
};
//Start the internal http server
auth.StartHttpServer();
//When we got our response
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent; // <-- Error here!
//Start
auth.DoAuth();
}
static void auth_OnResponseReceivedEvent(Token token, string state, string error)
{
//stop the http server
auth.StopHttpServer();
var spotify = new SpotifyWebAPI()
{
TokenType = token.TokenType,
AccessToken = token.AccessToken
};
//We can now make calls with the token object
}
编译错误:
No overload for 'auth_OnResponseReceivedEvent' matches delegate 'SpotifyAPI.Web.Auth.ImplicitGrantAuth.OnResponseReceived'
我不确定我是否忽略了一些非常简单的东西,或者我是否需要特别添加一些东西。我对使用事件处理程序也很陌生。
您的 auth_OnResponseReceivedEvent
方法中的参数过多。 OnResponseReceived
委托中没有string state
参数:
public delegate void OnResponseReceived(Token token, String error);
public event OnResponseReceived OnResponseReceivedEvent;