Auties00 / Cobalt

Standalone unofficial fully-featured Whatsapp Web and Mobile API for Java and Kotlin
MIT License
616 stars 180 forks source link

"too_recent" error on registration #412

Closed rebeccachipps closed 7 months ago

rebeccachipps commented 8 months ago
package com.example;

import it.auties.whatsapp.api.Whatsapp;
import it.auties.whatsapp.api.MobileRegistrationBuilder;
import it.auties.whatsapp.model.companion.CompanionDevice;
import it.auties.whatsapp.model.mobile.VerificationCodeMethod;
import it.auties.whatsapp.model.signal.auth.UserAgent;
import it.auties.whatsapp.model.signal.auth.Version;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
        long phoneNumber = 1925****217L;
        Whatsapp.mobileBuilder()
                .newConnection(phoneNumber)
                .unregistered()
                .verificationCodeMethod(VerificationCodeMethod.SMS)
                .verificationCodeSupplier(() -> {
                    System.out.println("Enter OTP : ");
                    return new Scanner(System.in).nextLine().trim();
                })
                .register(phoneNumber)
                .join();
    }
}

i use this code to register on WhatsApp, but after a long time, no error or event occurs. also, when I put the device on Android (.device(CompanionDevice.android())), no error or event occurs even after a long time. but when I set the device to iOS (.device(CompanionDevice.ios())) I encounter the following error every time I request

{
  "reason": "too_recent",
  "status": "fail",
  "retry_after": 300,
  "sms_wait": 300,
  "voice_wait": 300,
  "login": "1925****217",
  "wa_old_wait": 300,
  "email_otp_wait": 300
}

i tested more than 20 numbers and also each number with a different IP but still the same error occurs how can I fix this problem?

oldman3344 commented 7 months ago

I followed your code and tested it with different country codes, but I keep getting the exception 'Exception in thread "main" java.util.concurrent.CompletionException: java.net.ConnectException.' What could be the possible reasons for this?

Whatsapp.mobileBuilder() .newConnection(phoneNumber) .device(CompanionDevice.android()) .unregistered() .verificationCodeMethod(VerificationCodeMethod.SMS) .verificationCodeSupplier(() -> { System.out.println("Enter OTP : "); return new Scanner(System.in).nextLine().trim(); }) .register(phoneNumber) .join();