我正在使用Node.js GramJS Telegram npm包来查询Telegram API。我还用@mtproto/core测试了这一点,两个NPM包都得到了相同的AUTH_KEY_UNREGISTERED
和API_ID_INVALID
RPCErrors。
我从站点将api_id和api_hash复制到apiId
和apiHash
变量中。
我不知道是否有人可以测试这段代码,看看它是否按原样工作,也许这是Telegram和我收到的API令牌的问题?
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions/index.js";
const apiId = 1234567;
const apiHash = "this has the api_hash from the telegram website in my code";
const session = new StringSession("");
const client = new TelegramClient(session, apiId, apiHash);
(async function run() {
await client.connect();
console.log("You should now be connected.");
console.log(client.session.save());
const result = await client.invoke(
new Api.channels.GetParticipant({
channel: new Api.InputChannel({ channelId: -1001536877977 }),
participant: new Api.ChannelParticipant({ userId: 1425866959 }),
}),
);
console.log(result); // prints the result
})();
发布于 2021-07-16 22:53:31
好吧,我解决了我的问题。我选择使用Logging in as a User选项,在该选项中输入您的Telegram手机号码进行身份验证。
这是可行的,所以我可能会用Redis添加一些会话存储,这样我就不必在每次启动应用程序时重新输入我的号码来重新进行身份验证。
如果其他人遇到这个问题,我只想发布一个答案:)
(async function run() {
// authenticate as a user
await client.start({
phoneNumber: async () => await input.text("number ?"),
password: async () => await input.text("password?"),
phoneCode: async () => await input.text("Code ?"),
onError: (err) => console.log(err),
});
await client.connect();
console.log("You should now be connected.");
console.log(client.session.save());
const result = await client.invoke(
new Api.channels.GetParticipant({
channel: -1001536877977,
participant: "ajroos",
}),
);
console.log(result); // prints the result
})();
https://stackoverflow.com/questions/68410128
复制相似问题