Reputation: 71
I am using a private Instagram API for C# known as InstaSharper, I built my code like the Documentation found on its GitHub but no matter what I do I keep getting the same Error when trying to Upload a Picture. My Code is as Followed: `
private static IInstaApi _instaApi;
private static async Task Main(string[] args)
{
// Define user credentials
var userCredentials = new UserSessionData
{
UserName = "MyInstagramUsername",
Password = "MyInstagramPassword"
};
_instaApi = InstaApiBuilder.CreateBuilder()
.SetUser(userCredentials)
.UseLogger(new DebugLogger(LogLevel.All))
.Build();
var loginResult = await _instaApi.LoginAsync();
if (loginResult.Succeeded)
{
Console.WriteLine("Logged in successfully.");
await InsertImage(@"C:\Insta\testImage.png");
}
else
{
Console.WriteLine($"Failed to log in: {loginResult.Info.Message}");
}
}
public static async Task InsertImage(string _path)
{
Console.WriteLine(new Uri(Path.GetFullPath(_path), UriKind.Absolute).LocalPath);
var mediaImage = new InstaImage
{
URI = new Uri(Path.GetFullPath(_path), UriKind.Absolute).LocalPath,
Width = 1080,
Height = 1080
};
Console.WriteLine("Media Made");
var result = await _instaApi.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}");
Console.WriteLine("End of Function");
}
`
and the Error Unable to upload photo: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
keeps happening on the var result = await _instaApi.UploadPhotoAsync(mediaImage, "Caption");
I've tried everything I was able to find in the Offical Documentation.
Update:
It was suggested by @dbc that I log everything ToString in the Console, which showed that I was receiving an HTML Document instead of the Expected JSON.
<html lang="None" class="no-js not-logged-in ">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> Page Not Found • Instagram </title>
<meta name="robots" content="noimageindex, noarchive">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#ffffff">
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">
<link rel="manifest" href="/data/manifest.json">
</head>
However I have not Managed to fix it.
Upvotes: 1
Views: 62