ramtinak / InstagramApiSharp

A complete Private Instagram API for .NET (C#, VB.NET).
MIT License
795 stars 239 forks source link

solved #213

Closed reefer closed 5 years ago

reefer commented 5 years ago

hello, im trying to upload a picture with a caption to my instagram account from winforms, im trying to select the jpeg with button3 click then using button2 to upload, can you please help i get this error , Thank you

System.NullReferenceException: 'Object reference not set to an instance of an object.'

private void button3_Click(object sender, EventArgs e) { OpenFileDialog opf = new OpenFileDialog(); opf.Filter = "Choose Image(.jpg;)|.jpg;"; if (opf.ShowDialog() == DialogResult.OK) { textBox5.Text = opf.FileName; string path = textBox5.Text; } } private async void button2_Click(object sender, EventArgs e) {

        var caption = textBox4.Text;
        string imgPath = textBox5.Text;
        var img = new InstaImageUpload
        {
            Height = 1080,
            Width = 1080,
            Uri = imgPath
        };
        img.UserTags.Add(new InstaUserTagUpload
        {
            Username = "eric24",
            X = 0.5,
            Y = 0.5

        });

      (this is the line that it throws the exception)
       var result = await InstaApi.MediaProcessor.UploadPhotoAsync(img, "sickkk");
      (System.NullReferenceException: 'Object reference not set to an instance of an object.')

        if(result.Succeeded)
        {
            MessageBox.Show("Media Created: " + result.Value.Pk + "Caption: " + result.Value.Caption);
        }

    }
reefer commented 5 years ago

solved the problem by uploading the image with bytes