感谢这个问题和Andre Soares,我设法编写了正确的代码,用于连接WhatsApp并发送简单的消息.
using System;
using WhatsAppApi;
using WhatsAppApi.Register;
namespace WhatsAppBot
{
class Program
{
static void Main(string[] args)
{
WhatsApp wa = new WhatsApp("********", "********", "sakher", false, false);
// I tried with phone numbers like "38xxxxxxx", "+38xxxxxxx".
// The phone number wasn't previously registered in WhatsApp.
// Password was generated using WART.
wa.OnConnectSuccess += () =>
{
Console.WriteLine("Connected");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
Console.WriteLine("Connection success!");
wa.SendMessage("********", "Hello World!");
// Number is correct and registered in WhatsApp
Console.WriteLine("Message sent!");
};
wa.OnLoginFailed += data => {
Console.WriteLine("Login failed: {0}", data);
// Login failed: not-authorized
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
Console.WriteLine("Connect failed: {0}", ex.StackTrace);
};
wa.Connect();
wa.Disconnect();
Console.WriteLine("BYE");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在WART中为相同的数字生成了多次密码,但都没有.
一个应用程序简单地说:登录失败:未经授权.
也许,有人知道如何解决这个问题?
https://drive.google.com/file/d/0BwBxpfm3kmmgNGtKNkRTRF9fS0k/view?pli=1 使用这个对我有用的dll,尝试使用新的whats应用程序,从wart新注册
使用的代码是
WhatsApp wa = new WhatsApp(sender, password, nickname, true, true);
wa.OnConnectSuccess += () => {
Console.WriteLine("Connected");
wa.OnLoginSuccess += (phoneNumber, data) => {
Console.WriteLine("Connection success!");
wa.SendMessage(target, "testing C# Api,sent via C#");
Console.WriteLine("Message sent!");
};
wa.OnLoginFailed += (data) => {
Console.WriteLine("Login failed: {0}", data);
};
wa.Login();
};
wa.OnConnectFailed += (ex) => {
Console.WriteLine("Connect failed: {0}", ex.StackTrace);
};
wa.Connect();
Console.WriteLine("END");
Run Code Online (Sandbox Code Playgroud)