Open Dn9x opened 1 year ago
would be great if you wrote the issue in english.
You seem to be using the wrong IP.
client.session.setDC(2, "149.154.167.40", 443);
use that
I have used this for testing, same error。
client.session.setDC(2, "149.154.167.40", 443);
I have searched all kinds of ways on the search and have tested, but still the same error.
Is this related to the ip? I also use the ip of several countries and regions and still get the same error.
I don't think so. I just copy pasted your code and changed the ip and it worked fine for me.
Can you tell me where your ip belongs to? I tested the Hong Kong ip, Singapore, the United States, and Japan have not been able to, I am not sure why?
my IP has nothing to do with this. this is the code i used:
const phoneNumber = "9996623848";
const phoneCode = "22222";
const createClient = async (stringSession: string) => {
const session = new StringSession(stringSession);
const options = { connectionRetries: 5, baseLogger: new Logger("debug") };
const client = new TelegramClient(session, apiId, apiHash, options);
client.session.setDC(2, "149.154.167.40", 443); // 这里是我的apikey里面的ip和端口
await client.connect();
return client;
};
const getLoginCodeCommand = (phoneNumber: string) => {
const settings = new Api.CodeSettings();
const args = { phoneNumber, apiId, apiHash, settings };
return new Api.auth.SendCode(args);
};
(async () => {
const client = await createClient("");
const response = await client.invoke(getLoginCodeCommand(phoneNumber));
console.log('response:', response);
const { phoneCodeHash } = response;
const args = { phoneNumber, phoneCode, phoneCodeHash };
console.log('args', args);
const result = await client.invoke(new Api.auth.SignIn(args));
console.log("RESULT", result);
})();
Make sure there is no cash being used and check the logs to see if the correct telegram IP is being used .
setdc ip from this:
Is it possible that the telegram server has been unsuccessful in identifying my device? I'll try another device.
no it has nothing to do with your device. Have you tried the code I sent and checked the logs ?
yes, sign in is sucess. but signup fail:
const phoneNumber = "99966273168";
const phoneCode = "22222";
const createClient = async (stringSession) => {
const session = new StringSession(stringSession);
const options = { connectionRetries: 5, baseLogger: new Logger("debug") };
const client = new TelegramClient(session, apiId, apiHash, options);
client.session.setDC(2, "149.154.167.40", 443); // 这里是我的apikey里面的ip和端口
await client.connect();
return client;
};
const getLoginCodeCommand = (phoneNumber) => {
const settings = new Api.CodeSettings();
const args = { phoneNumber, apiId, apiHash, settings };
return new Api.auth.SendCode(args);
};
(async () => {
const client = await createClient("");
const response = await client.invoke(getLoginCodeCommand(phoneNumber));
console.log('response:', response);
const { phoneCodeHash } = response;
const args = { phoneNumber, phoneCodeHash, firstName: "liu", lastName: "some" };
console.log('args', args);
// const result = await client.invoke(new Api.auth.SignIn(args));
const result = await client.invoke(
new Api.auth.SignUp(args)
);
console.log("RESULT", result);
})();
result :
I don't think that's not how sign up works.
you have first to try to sign in. If telegram returns Api.AuthorizationSignUpRequired
then you can use sign up.
I see, thank you, I will test it.
@Dn9x have you succeed?
我参考了这个issues: https://github.com/gram-js/gramjs/issues/70 完整代码如下:
一直提示号码无效: