如何使用Instasharp

时间:2015-05-05 18:46:20

标签: c# instagram instasharp

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

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

所以我用我的客户端和我的秘密创建了一个配置,并用它创建了一个位置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 :(得分: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, long位置,其中大多数地方的地点名称为Lyon