0

所以我正在使用 InstaSharper,我想让用户输入他们的目标用户的名字,但是,它没有处理数据,它什么也不做。这是我的代码:

    class Program
{

    //username and pass
    #region Hidden
    #endregion
    private static UserSessionData user;
    private static IInstaApi api;
    static void Main(string[] args)
    {
        string inputUser;
        string inputPass;

        Console.WriteLine("Enter the username");
        inputUser = Console.ReadLine();
        Console.WriteLine("Enter your password:");
        inputPass = Console.ReadLine();

        user = new UserSessionData();
        user.UserName = inputUser;
        user.Password = inputPass;

        Login();
        Console.Read();
    }

    public static async void Login()
    {
        //login attempt

        api = InstaApiBuilder.CreateBuilder()
            .SetUser(user)
            .UseLogger(new DebugLogger(LogLevel.Exceptions))
            .Build();

        var loginRequest = await api.LoginAsync();
        if (loginRequest.Succeeded)
        {
            string targetUser;
            Console.WriteLine("Logged in!\n\t");
            Console.WriteLine("Now enter the target user");
            targetUser = Console.ReadLine();
            PullUserPosts(targetUser);
        }
        else
        {
            Console.WriteLine("Error logging in, are you sure you have entered the right credentials?");
        }

    }

    public static async void PullUserPosts(string userToScrape)
    {
        //instagram show followers demo
        var userinfo = await api.GetUserInfoByIdAsync(123456789);
        Console.WriteLine($"USER: {userinfo.Value.FullName}\n\tFollowers: {userinfo.Value.FollowerCount} \n \t Is it verified?\n\t {userinfo.Value.IsVerified}\n\t\n\t");

        Console.WriteLine("Loading all posts and captions by target user.. \n\t");

        IResult<InstaMediaList> media = await api.GetUserMediaAsync(userToScrape, PaginationParameters.MaxPagesToLoad(5));
        List<InstaMedia> mediaList = media.Value.ToList();

        for (int i = 0; i < mediaList.Count; i++)
        {
            InstaMedia m = mediaList[i];
            if (m != null && m.Caption != null)
            {
                string captionText = m.Caption.Text;
                if (captionText != null)
                {
                    if (m.MediaType == InstaMediaType.Image)
                    {
                        for (int x = 0; x < m.Images.Count; x++)
                        {
                            if (m.Images[x] != null && m.Images[x].URI != null)
                            {
                                Console.WriteLine($"\n\t{captionText}\n\t");
                                string uri = m.Images[x].URI;

                                Console.Write($"{uri}\n\t");
                            }
                        }
                    }
                }
            }
        }

它设法登录,但是当我告诉用户“现在输入目标用户”时,什么也没发生。有谁知道如何修理它?

4

0 回答 0