从电报用户名中查找用户ID

问题描述:

getFullUser Telegram API中的一种方法,通过ID返回扩展的用户信息。从电报用户名中查找用户ID

https://core.telegram.org/method/users.getFullUser

我的问题是如何从电报的用户名获得用户ID用这种方法使用。 例如,这是我的用户名:telegram.me/androidsoftware。 是否存在从用户名返回userId的方法?

我在电报源代码 中发现了此代码,但我不知道如何将此代码写入C#以与MTProto一起使用。

if (username != null) { 
     TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername(); 
     req.username = username; 
     requestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { 
      @Override 
      public void run(final TLObject response, final TLRPC.TL_error error) { 
       AndroidUtilities.runOnUIThread(new Runnable() { 
        @Override 
        public void run() { 
         if (!LaunchActivity.this.isFinishing()) { 
          try { 
           progressDialog.dismiss(); 
          } catch (Exception e) { 
           FileLog.e("tmessages", e); 
          } 
          if (error == null && actionBarLayout != null) { 
           final TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response; 
           MessagesController.getInstance().putUsers(res.users, false); 
           MessagesController.getInstance().putChats(res.chats, false); 
           MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, false, true); 

           if (botChat != null) { 
            final TLRPC.User user = !res.users.isEmpty() ? res.users.get(0) : null; 
            if (user == null || (user.flags & TLRPC.USER_FLAG_BOT) != 0 && (user.flags & TLRPC.USER_FLAG_BOT_CANT_JOIN_GROUP) != 0) { 
             try { 
              Toast.makeText(LaunchActivity.this, LocaleController.getString("BotCantJoinGroups", R.string.BotCantJoinGroups), Toast.LENGTH_SHORT).show(); 
             } catch (Exception e) { 
              FileLog.e("tmessages", e); 
             } 
             return; 
            } 
            Bundle args = new Bundle(); 
            args.putBoolean("onlySelect", true); 
            args.putInt("dialogsType", 2); 
            args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupTitle", R.string.AddToTheGroupTitle, UserObject.getUserName(user), "%1$s")); 
            DialogsActivity fragment = new DialogsActivity(args); 
            fragment.setDelegate(new DialogsActivity.MessagesActivityDelegate() { 
             @Override 
             public void didSelectDialog(DialogsActivity fragment, long did, boolean param) { 
              NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); 
              MessagesController.getInstance().addUserToChat(-(int) did, user, null, 0, botChat, null); 
              Bundle args = new Bundle(); 
              args.putBoolean("scrollToTopOnResume", true); 
              args.putInt("chat_id", -(int) did); 
              actionBarLayout.presentFragment(new ChatActivity(args), true, false, true); 
             } 
            }); 
            presentFragment(fragment); 
           } else { 
            Bundle args = new Bundle(); 
            if (!res.chats.isEmpty()) { 
             args.putInt("chat_id", res.chats.get(0).id); 
            } else { 
             args.putInt("user_id", res.users.get(0).id); 
            } 
            if (botUser != null) { 
             args.putString("botUser", botUser); 
            } 
            ChatActivity fragment = new ChatActivity(args); 
            NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); 
            actionBarLayout.presentFragment(fragment, false, true, true); 
           } 
          } else { 
           try { 
            Toast.makeText(LaunchActivity.this, LocaleController.getString("NoUsernameFound", R.string.NoUsernameFound), Toast.LENGTH_SHORT).show(); 
           } catch (Exception e) { 
            FileLog.e("tmessages", e); 
           } 
          } 
         } 
        } 
       }); 
      } 
     }); 
    }