How to make a request with Instasharp

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

Here is my code, in this one I just want to make a simple query (getting the location by their latitude and longitude) to see how it works.

So, I created a config with my client and my secret, and I used that to create the Location Endpoint

. But after execution 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);
}

      

Do you have any solutions or tips that I could use? Thank you for your help.

+3


source to share


1 answer


This is freezing because you are not using a keyword await

in combination with a keyword async

. Also, it is result1.Data

not result1.Result.Data

(when you iterate over the returned list of locations.)

Try it.



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 lat, long

that you have in your code, and the place (s) name was Lyon

in most of them.

0


source







All Articles