3

我必须用 instasharp 做一些请求,但我不知道该怎么做,我在网站上搜索后尝试了一些东西,但它使 Visual Studio 冻结。

这是我的代码,在这个代码中,我只想提出一个简单的请求(通过纬度和经度获取位置),以了解它是如何工作的。

所以我用我的客户和我的秘密创建了一个配置,并用它来创建一个 Location Endpoint。但是在做之后result1.Wait(),它会冻结。

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);
}

你有什么我可以使用的解决方案或技巧吗?谢谢您的帮助。

4

1 回答 1

0

冻结是因为您没有将await关键字与关键字一起使用async。此外,它result1.Data不是result1.Result.Data(当您循环浏览返回的位置列表时。)

尝试这个。

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);
}

我在您的代码中20获得了您的默认位置,并且大多数位置的名称都在其中。lat, longLyon

于 2015-08-20T06:39:48.120 回答