首页 > 解决方案 > C# InstaSharper:无法上传照片:解析值时遇到意外字符:S. Path '', line 0, position 0

问题描述

我将此库用作 instagram bot 程序的 NuGet 包(InstaSharper):https ://github.com/a-legotin/InstaSharper

InsertImage();函数中,该函数用于将照片上传到 Instagram 页面,在解析时,程序遇到问题并控制台返回:

登录!无法上传照片:解析值时遇到意外字符:S. Path '', line 0, position 0。

我尝试使用不同的路径和图像类型,但同样的事情发生了。

可能是什么问题以及如何解决?

这些是主要功能:

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

            Login();
            Console.Read();
        }

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

            var loginRequest = await api.LoginAsync();
            if (loginRequest.Succeeded)
            {
                Console.WriteLine("Loged in!");
                InsertImage(@"C:\test.jpg", "Testing");
            }
            else Console.WriteLine("Unable to log in: " + loginRequest.Info.Message);
        }

public static async void InsertImage(string _path, string _caption)
        {
            var mediaImage = new InstaImage
            {
                Height = 1080,
                Width = 1080,
                URI = new Uri(Path.GetFullPath(_path), UriKind.Absolute).LocalPath
            };
            var result = await api.UploadPhotoAsync(mediaImage, _caption);
            if (result.Succeeded == true) Console.WriteLine($"Media created: {result.Value.Pk}, {result.Value.Caption}");
            else Console.WriteLine($"Unable to upload photo: {result.Info.Message}");

        }

标签: c#jsonparsingimage-uploadinginstasharp

解决方案


似乎 InstaSharper Nuget 包没有更新,我已经从 Github 下载它并在我的项目中使用它,它对我有用

希望这可以帮助


推荐阅读