ramtinak / InstagramApiSharp

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

Need help with Uploading an Image #230

Closed tylastrog closed 5 years ago

tylastrog commented 5 years ago

I've:

Issue category

Language

Usage

Operating System

Describe your issue

I am new to C# and wanted to try and make a bot as my first program. I am using this code. It logs in correctly, but it does not upload the image. I've been looking through everything and none of the SOLVED solutions are helping me. Thanks :-)

namespace InstaBot
{
    class Program
    {
        private const string username = "username";
        private const string password = "password";

        private static UserSessionData user;
        private static IInstaApi api;

        public static void Main(string[] args)
        {
            user = new UserSessionData();
            user.UserName = username;
            user.Password = password;
            Login();
            Console.Read();
        }

        public static async void Login()
        {
            var delay = RequestDelay.FromSeconds(2, 2);

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

            var loginRequest = await api.LoginAsync();
            if (loginRequest.Succeeded)
            {
                Console.Write("logged in");
            }
            else
            {
                Console.Write("error logging in");
            }
        }

        public async Task DoShowWithProgress()
        {
            var mediaImage = new InstaImageUpload
            {
                Height = 600,
                Width = 600,
                Uri = @"d:\logo.jpg"
            };

            var result = await api.MediaProcessor.UploadPhotoAsync(mediaImage, "if i did this correctly, this image was uploaded by a bot :-) (<3 tyler>");
            Console.WriteLine(result.Succeeded ? $"Media created: {result.Value.Pk}, {result.Value.Caption}" : $"Unable to upload photo: {result.Info.Message}");
        }
    }
}
duplicate-issues[bot] commented 5 years ago

Hey @tylastrog,

We did a quick check and this issue looks very darn similar to

This could be a coincidence, but if any of these issues solves your problem then I did a good job :smile:

If not, the maintainers will get to this issue shortly.

Cheers, Your Friendly Neighborhood ProBot

ramtinak commented 5 years ago

Can you post your debug logs? Set LogLevel.Exceptions to LogLevel.All and post it here (remove image bytes from your debugs)

tylastrog commented 5 years ago

4/3/2019 4:00:37 PM: Request: https://i.instagram.com/ 4/3/2019 4:00:39 PM: Response: GET https://www.instagram.com/ [OK] 4/3/2019 4:00:39 PM: Content: 4/3/2019 4:00:39 PM: got html content! 4/3/2019 4:00:39 PM: Response: GET https://www.instagram.com/ [OK] 4/3/2019 4:00:39 PM: Content: 4/3/2019 4:00:39 PM: got html content! 4/3/2019 4:00:39 PM: ---------------------------------------------------------------------------------------------------- 4/3/2019 4:00:39 PM: Request: POST https://i.instagram.com/api/v1/accounts/login/ 4/3/2019 4:00:39 PM: Headers: 4/3/2019 4:00:39 PM: Accept-Language:["en-US"] 4/3/2019 4:00:39 PM: X-IG-Capabilities:["3brTvw=="] 4/3/2019 4:00:39 PM: X-IG-Connection-Type:["WIFI"] 4/3/2019 4:00:39 PM: User-Agent:["Instagram","86.0.0.24.87","Android","(16/4.1; 640dpi; 1440x2560; samsung; lt01wifiue; lt01wifiue; SM-T310; en_US; 147375143)"] 4/3/2019 4:00:39 PM: X-IG-App-ID:["567067343352427"] 4/3/2019 4:00:39 PM: Host:["i.instagram.com"] 4/3/2019 4:00:39 PM: Properties: { "X-Google-AD-ID": "d125da2a-99bf-46d5-abd9-e03e59db3c47" } 4/3/2019 4:00:39 PM: Content: 4/3/2019 4:00:39 PM: signed_body=88deaacd0a758b6d999fb3055896620d68926797d705ba63037f75c6ba863175.{"phone_id":"689ea127-46c3-4141-950b-c25113c47159","username":"---","adid":"6da9d897-f8b2-4aa0-99a8-06d937062d43","guid":"8d322a2b-e93e-42c9-ab09-535951fc25d4","device_id":"android-1501cd353a3386cb","_uuid":"8d322a2b-e93e-42c9-ab09-535951fc25d4","google_tokens":"[]","password":"---","login_attempt_count":"1"}&ig_sig_key_version=4 4/3/2019 4:00:42 PM: Response: POST https://i.instagram.com/api/v1/accounts/login/ [OK] 4/3/2019 4:00:42 PM: Content: 4/3/2019 4:00:42 PM: {"logged_in_user": {"pk": ---, "username": "---", "full_name": "---", "is_private": true, "profile_pic_url": "---", "profile_pic_id": "---", "is_verified": false, "has_anonymous_profile_picture": false, "can_boost_post": false, "is_business": false, "account_type": 1, "is_call_to_action_enabled": null, "can_see_organic_insights": false, "show_insights_terms": false, "reel_auto_archive": "unset", "has_placed_orders": false, "allowed_commenter_type": "any", "nametag": {"mode": 1, "gradient": "0", "emoji": "\ud83d\ude00", "selfie_sticker": "0"}, "allow_contacts_sync": true, "phone_number": ""}, "status": "ok"}

That is everything sent into my console after changing to LogLevel.All, I removed the private info of course

ramtinak commented 5 years ago

Ops, I didn't read your question at all! sorry. in this section:

        if (loginRequest.Succeeded)
        {
            Console.Write("logged in");
        }

just put await DoShowWithProgress(); after Console.Write...

        if (loginRequest.Succeeded)
        {
            Console.Write("logged in");
            await DoShowWithProgress();
        }

Good luck.

tylastrog commented 5 years ago

yay! thanks :-)