9

Thanks to this question and Andre Soares I have managed to write correct code for connecting to WhatsApp and sending simple message.

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");
        }
    }
}

I have generated password in WART for several times for the same number, but none worked.

An App simply says: Login failed: not-authorized.

Perhaps, someone knows how to fix this?

2
  • 1
    I'm also getting the same problem. Commented Sep 2, 2015 at 7:18
  • 1
    It's almost definitely because whatsapp changed their authentication and broke WART because not only do they not support a public API, they explicitly try to stop people from using their service without their app.
    – Rob
    Commented Sep 23, 2015 at 6:15

2 Answers 2

2
private void button1_Click(object sender, EventArgs e)
{
     //Send To details
     string Phnumber = textBox1.Text;
     string message = textBox2.Text;

     //send From details

     string FromNumber = "917673943979";
     string password = "aaRvxtEbePyI/uBOqpqw9yeHlys=";
     string nickName = "Dayakar";

     WhatsApp wap = new WhatsApp(FromNumber, password, nickName, false, false);
     wap.OnConnectSuccess += () =>
         {
             MessageBox.Show("Connected to whatsapp SuccessFully...");

             wap.OnLoginSuccess += (PhoneNumber, data) =>
             {
                 MessageBox.Show("Enterned");
                 wap.SendMessage(Phnumber, message);
                 MessageBox.Show("Message Sent Successfully...");
             };

             wap.OnLoginFailed += (data) =>
             {
                 MessageBox.Show(data);
                 MessageBox.Show("Yes Failed login : {0}", data);
             };

             wap.Login();
         };

     wap.OnConnectFailed += (ex) =>
         {
             MessageBox.Show("Conncetion Failure");
         };

     wap.Connect();
 }
1
  • It is working but after few times of run and restart the program I get Login Failed : not-authorized ! So how to solve this issue ? is there is a time to reconnect ?
    – Maadh
    Commented Jan 3, 2016 at 7:35
0

https://drive.google.com/file/d/0BwBxpfm3kmmgNGtKNkRTRF9fS0k/view?pli=1 use this dll this worked for me , try to use a new whats app no , freshly registered from wart

code used was

      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");
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.