将Autoid函数分配给Auth事件时编译错误

时间:2015-10-03 17:55:57

标签: c# api authentication spotify

我正在构建一个需要Spotify来使用ImplicitGrantAuth对用户进行身份验证的应用程序。我已经在Spotify的开发站上设置了我的应用程序并且有一个ClientID。我在这个应用程序中使用JohnnyCrazy/SpotifyAPI-NET

  • 可以找到隐式授权身份验证的API文档 here

  • 可以找到Spotify的Implicit Grant Flow文档 here

  • 可以找到ImplicitGrantAuth的原始班级 here

代码段:

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
}

编译错误:

  

没有过载&#39; auth_OnResponseReceivedEvent&#39;匹配委托&#39; SpotifyAPI.Web.Auth.ImplicitGrantAuth.OnResponseReceived&#39;

我不确定我是否忽略了一些非常简单的东西,或者我是否需要特别添加一些东西。我对使用事件处理程序也很陌生。

1 个答案:

答案 0 :(得分:1)

auth_OnResponseReceivedEvent方法中的参数太多了。 string state委托中没有OnResponseReceived参数:

public delegate void OnResponseReceived(Token token, String error);

public event OnResponseReceived OnResponseReceivedEvent;