whatsapp c# Auth response error

梦想的初衷 提交于 2019-12-23 22:26:32

问题


I'm using the last nuget version for whatsapp: WhastApp API 1.2.2 and reading tutorials about configure my whatsapp in my application. I'm using my localhost to test and my code is:

string from = "503XXXX";
            string to = "503XXXX";
            string msg = "lorem ipsum";

            WhatsApp wa = new WhatsApp(from, "jd8eY3FXXXXXXXXXXXXXXXXXXX", "MrMins", true);

            wa.OnConnectSuccess += () =>
                                       {
                                           wa.OnLoginSuccess += (phoneNumber, data) =>
                                                                    {
                                                                        wa.SendMessage(to, msg);
                                                                    };
                                       };

            wa.OnLoginFailed += (data) =>
            {
                //Fail message
            };

            wa.Login();

            wa.OnConnectFailed += (ex) =>
            {
                //ConnectionFailed
            };

            wa.Connect();
            wa.SendMessage(to, msg);
            wa.Disconnect();

I'm getting the error:

Auth response error 

I updated my whatsapp password with WART and logged me out from my whatsapp mobile (I think is the correct behavior), but is still not working.

What is wrong with my codes?


回答1:


I guess your problem is, that you try to send a message also if the connection failed. Try this instead of your code to send a message:

WhatsApp wa = new WhatsApp("your number", "your password", "your nickname", false, false);
wa.OnConnectSuccess += () =>
{
    Response.Write("connect");
    wa.OnLoginSuccess += (phno,data) =>
    {
        wa.SendMessage("to", "msg");
    };

    wa.OnLoginFailed += (data) =>
    {
        Response.Write("login failed"+data);
    };
    wa.Login();
};
wa.OnConnectFailed+= (ex)=>
{
    Response.Write("connection failed");
}

This avoids the sending if the connection failed.

PS: If in your code the connection succeeded you would send the message twice.




回答2:


Imagine, your code area is: 503 and your phone number is 555555555555

WhatsApp wa = new WhatsApp("503555555555555", "get the password using WART", "your nickname", false, false);
            wa.OnConnectSuccess += () =>
            {
                Response.Write("connect");
                wa.OnLoginSuccess += (phno,data) =>
                {
                    wa.SendMessage("Destinatino number (50377777777777)", "Youre custom message");
                };

                wa.OnLoginFailed += (data) =>
                {
                    Response.Write("login failed"+data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
                                      {
                                          Response.Write("connection failed");
                                      }
                ;

            wa.Connect();


来源:https://stackoverflow.com/questions/35071540/whatsapp-c-sharp-auth-response-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!