【问题标题】:Compile Error While Assigning Void Function to Auth Event将 void 函数分配给 Auth 事件时编译错误
【发布时间】:2015-12-31 18:07:28
【问题描述】:

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

  • 可以找到隐式授权认证的 API 文档 here.

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

  • 可以找到ImplicitGrantAuth的原始类 here

代码 sn-p:

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
}

编译错误:

“auth_OnResponseReceivedEvent”没有过载匹配委托“SpotifyAPI.Web.Auth.ImplicitGrantAuth.OnResponseReceived”

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

【问题讨论】:

    标签: c# api authentication spotify


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-27
      • 2023-03-31
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      相关资源
      最近更新 更多