3

I have to do some requests with instasharp but I don't know how to do it, I tried something after searching on the site but it makes Visual Studio freeze.

Here is my code, in this one I just want to make a simple request (getting location by their latitude and longitude) in order to learn how does it work.

So I created a config with my client and my secret, and I used it to create a Location Endpoint. But after doing result1.Wait(), it freezes.

var clientID = "Myclient";
var clientSecret = "Mysecret";

InstaSharp.InstagramConfig config = new InstaSharp.InstagramConfig(clientID, clientSecret);

var location = new InstaSharp.Endpoints.Locations(config);

var result1 = location.Search(45.759723, 4.842223);

result1.Wait();

foreach (InstaSharp.Models.Location l in result1.Result.Data)
{
    MessageBox.Show(l.Name);
}

Have you any solutions or tips I could use? Thank you for your help.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Pop Grade
  • 47
  • 3

1 Answers1

0

It's freezing because you are not using the await keyword in conjunction with the async keyword. Also, it's result1.Data not result1.Result.Data (when you are looping through the returned list of locations.)

Try this.

var clientID = "Myclient";
var clientSecret = "Mysecret";

InstaSharp.InstagramConfig config = new InstaSharp.InstagramConfig(clientID, clientSecret);

var location = new InstaSharp.Endpoints.Locations(config);
var result1 = await location.Search(45.759723, 4.842223);
foreach (InstaSharp.Models.Location l in result1.Data)
{
    MessageBox.Show(l.Name);
}

I got the default 20 locations for the lat, long you have in your code, and the name of the place(s) were Lyon in most of them.

Shiva
  • 20,575
  • 14
  • 82
  • 112