如何使用Instasharp进行请求

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

你有什么解决方案或技巧可以提供吗?感谢您的帮助。

1个回答

0

出现冻结是因为您没有在async关键字与await关键字一起使用。此外,在循环返回的位置列表时,应该使用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, long坐标计算得出的,大部分地方的名称是Lyon


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接