首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >电报-获取AUTH_KEY_UNREGISTERED和API_ID_INVALID错误

电报-获取AUTH_KEY_UNREGISTERED和API_ID_INVALID错误
EN

Stack Overflow用户
提问于 2021-07-16 21:46:40
回答 1查看 459关注 0票数 1

我正在使用Node.js GramJS Telegram npm包来查询Telegram API。我还用@mtproto/core测试了这一点,两个NPM包都得到了相同的AUTH_KEY_UNREGISTEREDAPI_ID_INVALID RPCErrors。

我从站点将api_id和api_hash复制到apiIdapiHash变量中。

我不知道是否有人可以测试这段代码,看看它是否按原样工作,也许这是Telegram和我收到的API令牌的问题?

代码语言:javascript
运行
复制
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
})();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-16 22:53:31

好吧,我解决了我的问题。我选择使用Logging in as a User选项,在该选项中输入您的Telegram手机号码进行身份验证。

这是可行的,所以我可能会用Redis添加一些会话存储,这样我就不必在每次启动应用程序时重新输入我的号码来重新进行身份验证。

如果其他人遇到这个问题,我只想发布一个答案:)

代码语言:javascript
运行
复制
(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
})();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68410128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档