在instagram项目中错误'需要对象引用...' [英] Error 'an object reference is required …' in instagram project

查看:113
本文介绍了在instagram项目中错误'需要对象引用...'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个软件,您可以输入名称,它将在Instagram上搜索并抓取信息并显示给您。现在,我希望它在标签上显示名称和其他东西,但它说需要一个对象引用...。

i在lbl_Name中获取该错误,这是代码:





i'm making a software that you can type the name and it'll search on instagram and scrape the info and show it to you . now, i want it to show the name and other things on a label but it says an object reference is required ... .
i get that error in "lbl_Name" and this is the code:


public static async void PullUserPosts(string usertoscrape)
        {
            IResult<InstaUser> UserSearch = await api.GetUserAsync(usertoscrape);
            lbl_Name.text($"USER: {UserSearch.Value.FullName}\n\tFollowers: {UserSearch.Value.FollowersCount} \n\tVerified {UserSearch.Value.IsVerified}");

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










public partial class Form1 : Form
{
    private const string username = "";
    private const string password = "";

    private static UserSessionData user;

    private static IInstaApi api;


    private void Form1_Load(object sender, EventArgs e)
    {
        user = new UserSessionData();
        user.UserName = username;
        user.Password = password;

        Login();
        //lbl_Name.Text = $"USER: {UserSearch.Value.FullName}\n\tFollowers";
    }

    public Form1()
    {

        InitializeComponent();
    }

    private void Btn_Search_Click(object sender, EventArgs e)
    {



    }

    public static async void Login()
    {
        api = InstaApiBuilder.CreateBuilder()
            .SetUser(user)
            .UseLogger(new DebugLogger(LogLevel.Exceptions))
            .SetRequestDelay(TimeSpan.FromSeconds(8))
            .Build();


        var loginrequest = await api.LoginAsync();
        if (loginrequest.Succeeded)
        {
            MessageBox.Show("logged in");
            PullUserPosts("garyvee");
        }

        else
            MessageBox.Show("error logging in!\n" + loginrequest.Info.Message);
    }




    public static async void PullUserPosts(string usertoscrape)
    {
        IResult<InstaUser> UserSearch = await api.GetUserAsync(usertoscrape);
        lbl_Name.Text ($"USER: {UserSearch.Value.FullName}\n\tFollowers: {UserSearch.Value.FollowersCount} \n\tVerified {UserSearch.Value.IsVerified}");

        IResult<InstaMediaList> media = await api.GetUserMediaAsync(usertoscrape, PaginationParameters.MaxPagesToLoad(4));
        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)
                            {
                                MessageBox.Show($"\n\t{captiontext}\n\t");
                                string uri = m.Images[x].URI;

                                MessageBox.Show($"{uri}\n\t");

                            }
                        }
                    }
                }
            }
        }

    }


}



那么我应该怎么做才能让它在标签上显示结果?!

谢谢。



我尝试了什么:



messagebox.show它工作正常

但这不是我想要的。


so what should i do to make it show the results in a label ?!
thank you.

What I have tried:

messagebox.show and it worked fine
but that's not what i want .

推荐答案

USER:{UserSearch.Value.FullName} \ n \ tFollowers:{UserSearch .Value.FollowersCount} \ n\tVerified {UserSearch.Value.IsVerified});

IResult< InstaMediaList> media = await api.GetUserMediaAsync(usertoscrape,PaginationParameters.MaxPagesToLoad(4));
列表< InstaMedia> mediaList = media.Value.ToList();
"USER: {UserSearch.Value.FullName}\n\tFollowers: {UserSearch.Value.FollowersCount} \n\tVerified {UserSearch.Value.IsVerified}"); IResult<InstaMediaList> media = await api.GetUserMediaAsync(usertoscrape, PaginationParameters.MaxPagesToLoad(4)); List<InstaMedia> mediaList = media.Value.ToList();










public partial class Form1 : Form
{
    private const string username = "";
    private const string password = "";

    private static UserSessionData user;

    private static IInstaApi api;


    private void Form1_Load(object sender, EventArgs e)
    {
        user = new UserSessionData();
        user.UserName = username;
        user.Password = password;

        Login();
        //lbl_Name.Text =


USER:{UserSearch.Value.FullName} \ n \ tFollowers;
}

public Form1()
{

InitializeComponent();
}

private void Btn_Search_Click(object sender,EventArgs e)
{



}

public static async void Login()
{
api = InstaApiBuilder.CreateBuilder()
.SetUser(user)
.UseLogger(new DebugLogger(LogLevel.Exceptions))
.SetRequestDelay(TimeSpan.FromSeconds(8))
.Build();


var loginrequest = await api.LoginAsync();
if(loginrequest.Succeeded)
{
MessageBox.Show(登录);
PullUserPosts(garyvee);
}

else
MessageBox.Show(登录错误!\ n+ loginrequest.Info.Message);
}




public static async void PullUserPosts(string usertoscrape)
{
IResult< InstaUser> UserSearch = await api.GetUserAsync(usertoscrape);
lbl_Name.Text(
"USER: {UserSearch.Value.FullName}\n\tFollowers"; } public Form1() { InitializeComponent(); } private void Btn_Search_Click(object sender, EventArgs e) { } public static async void Login() { api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetRequestDelay(TimeSpan.FromSeconds(8)) .Build(); var loginrequest = await api.LoginAsync(); if (loginrequest.Succeeded) { MessageBox.Show("logged in"); PullUserPosts("garyvee"); } else MessageBox.Show("error logging in!\n" + loginrequest.Info.Message); } public static async void PullUserPosts(string usertoscrape) { IResult<InstaUser> UserSearch = await api.GetUserAsync(usertoscrape); lbl_Name.Text (


USER:{UserSearch.Value.FullName} \ n \ tFollowers:{UserSearch.Value.FollowersCount} \ n\tVerified { UserSearch.Value.IsVerified});

IResult< InstaMediaList> media = await api.GetUserMediaAsync(usertoscrape,PaginationParameters.MaxPagesToLoad(4));
列表< 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)
{
MessageBox.Show(
"USER: {UserSearch.Value.FullName}\n\tFollowers: {UserSearch.Value.FollowersCount} \n\tVerified {UserSearch.Value.IsVerified}"); IResult<InstaMediaList> media = await api.GetUserMediaAsync(usertoscrape, PaginationParameters.MaxPagesToLoad(4)); 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) { MessageBox.Show(


这篇关于在instagram项目中错误'需要对象引用...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆