首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在电报请求短信代码WTelegramClient C#时引发异常

如何在电报请求短信代码WTelegramClient C#时引发异常
EN

Stack Overflow用户
提问于 2022-02-28 00:00:57
回答 1查看 141关注 0票数 -2

我有这样的任务,我有现成的会话连接,有时会有一个不存在的会话,当您输入api_id、api_hash时,电话而不是授权要求我输入确认代码,所以我有一个问题--当它要求确认代码时,如何抛出异常退出这个会话并尝试输入新的会话?

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using TL;

namespace AccountConnections
{
    internal class Program
    {
        //static double version = 1.0;
        static List<Account> Accounts = new List<Account>();
        static Account Active_account = null;
        static string path = "json/";
        static void Main(string[] args)
        {
            Console.WriteLine("         --------------CONNECTION ACCOUNTS--------------");
            ImportData(path);
            ConnectionAccounts();
            Console.ReadKey();
        }
        static string Config(string what)
        {
            switch (what)
            {
                case "api_id": return Active_account.app_id.ToString();
                case "api_hash": return Active_account.app_hash;
                case "phone_number": return Active_account.session_file;
                case "verification_code": return "error"; //
                default: return null;// let WTelegramClient decide the default config
            }
        }

        static async void ImportData(string path) {
            var AllFiles = new DirectoryInfo(path).GetFiles();
            foreach (var file in AllFiles)
            {
                string data = File.ReadAllText(file.ToString());
                Account account = JsonSerializer.Deserialize<Account>(data)!;
                Accounts.Add(account);
            }
        }
        static async void ConnectionAccounts()
        {
            Active_account = Accounts[0];
            try{
                //throw exceptions and exit functions if the code asks 
                using var client = new WTelegram.Client(Config);
                var user = await client.LoginUserIfNeeded();
                Console.WriteLine($"We are logged-in as {user.username ?? user.first_name + " " + user.last_name} (id {user.id})");
            }
            catch (RpcException) { Console.WriteLine("Error"); }
        }
    }
    class Account
    {
        public string session_file { get; set; }
        public int app_id { get; set; }
        public string app_hash { get; set; }
    }
    class ConnactionExcaption : Exception
    {
        public ConnactionExcaption(){}
    }
}

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2022-02-28 16:14:51

你的问题不是很清楚,但我认为你的意思是,你已经通过从互联网上购买“现成的”会话,而这些并不是很好的工作。

这种做法违反了电报API TOS

2.1您必须为您的应用程序编写id

WTelegramClient不支持从外部库/供应商获得的会话文件。

我们也不为打算自动化大量用户帐户的开发人员提供特定的支持,因为这很可能是为了垃圾邮件/欺骗目的,这违背了电报TOS

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71289410

复制
相关文章

相似问题

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