使用Json.net Instagram的API [英] Instagram API using Json.net

查看:190
本文介绍了使用Json.net Instagram的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个桌面程序基本上我只是想收集每一次循环运行,这样可以节省从JSON的Instagram的ID已提供,然后移动到网络之一,时间的计时器或循环,使信息等等,我决定从提供的JSON的Instagram的看起来像这样只是一个单一的图像进行测试。

I'm working on a desktop program basically I'm just trying to collect information on a timer or loop so every time the loops runs it saves an ID from the JSON instagram has provided and then moves on to the net one and so on, I decided to test this on just a single image from the Json instagram provided which looks like this.

{"pagination":{"next_max_tag_id":"1399847337728968","deprecation_warning":"next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead","next_max_id":"1399847337728968","next_min_id":"1399847337793336","min_tag_id":"1399847337793336","next_url":"https:\/\/api.instagram.com\/v1\/tags\/snow\/media\/recent?access_token=+49749273.8a6c775.3e8cf314d75045e49ba17263d0bededa\u0026count=1\u0026max_tag_id=1399847337728968"},"meta":{"code":200},"data":[{"attribution":null,"tags":["ilovenorway","hiking","spring","sunny","blaaskjerdigen","bluebird","cloud","clouds","redbullnorge","sun","visit","snow","aalesund","sunnm\u00f8rsalps","nofilter","norway","redbull"],"type":"image","location":{"latitude":62.595061667,"longitude":6.735158333},"comments":{"count":0,"data":[]},"filter":"Normal","created_time":"1399822137","link":"http:\/\/instagram.com\/p\/n3JFAHGTdZ\/","likes":{"count":0,"data":[]},"images":{"low_resolution":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_a.jpg","width":306,"height":306},"thumbnail":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_s.jpg","width":150,"height":150},"standard_resolution":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_n.jpg","width":640,"height":640}},"users_in_photo":[{"position":{"y":0.040625,"x":0.06535948},"user":{"username":"redbullnorge","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_184192460_75sq_1342379531.jpg","id":"184192460","full_name":"Red Bull Norge"}},{"position":{"y":0.9609375,"x":0.06535948},"user":{"username":"redbull","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_476322_75sq_1334010289.jpg","id":"476322","full_name":"Red Bull"}}],"caption":{"created_time":"1399822137","text":"#nofilter #blaaskjerdigen #bluebird #cloud #clouds #sun #sunny #hiking #snow #spring #ilovenorway #redbull #redbullnorge #visit #norway #aalesund #sunnm\u00f8rsalps","from":{"username":"jooakimandersen","profile_picture":"http:\/\/images.ak.instagram.com\/profiles    \/profile_1246631612_75sq_1396821408.jpg","id":"1246631612","full_name":"Joakim Andersen"},"id":"718082592168556034"},"user_has_liked":false,"id":"718082591723960153_1246631612","user":{"username":"jooakimandersen","website":"","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_1246631612_75sq_1396821408.jpg","full_name":"Joakim Andersen","bio":"","id":"1246631612"}}]}


我想从信息获取从这个JSON文件中像这样


I'm trying to get from information from this json file like this

WebClient webClient = new WebClient();
var list = webClient.DownloadString("https://api.instagram.com/v1/tags/likeforlike/media/recent?access_token=" + Variables.authtoken + "&count=1");
dynamic parsedList = JsonConvert.DeserializeObject<dynamic>(list);

MessageBox.Show(parsedList.data.count.ToString());

但我不能从它那里得到任何东西,它会加载

but I can't get anything from it it'll load

 MessageBox.Show(parsedList.data.ToString());

得很好,但我无法得到任何更深比信息

just fine but I'm having trouble getting any deeper into the information than that

推荐答案

使用json2csharp( http://json2csharp.com ),我们得到以下类生成。

Using json2csharp (http://json2csharp.com) we get the following classes generated.

public class Pagination
{
    public string next_max_tag_id { get; set; }
    public string deprecation_warning { get; set; }
    public string next_max_id { get; set; }
    public string next_min_id { get; set; }
    public string min_tag_id { get; set; }
    public string next_url { get; set; }
}

public class Meta
{
    public int code { get; set; }
}

public class Location
{
    public double latitude { get; set; }
    public double longitude { get; set; }
}

public class Comments
{
    public int count { get; set; }
    public List<object> data { get; set; }
}

public class Likes
{
    public int count { get; set; }
    public List<object> data { get; set; }
}

public class LowResolution
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}

public class Thumbnail
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}

public class StandardResolution
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}

public class Images
{
    public LowResolution low_resolution { get; set; }
    public Thumbnail thumbnail { get; set; }
    public StandardResolution standard_resolution { get; set; }
}

public class Position
{
    public double y { get; set; }
    public double x { get; set; }
}

public class User
{
    public string username { get; set; }
    public string profile_picture { get; set; }
    public string id { get; set; }
    public string full_name { get; set; }
}

public class UsersInPhoto
{
    public Position position { get; set; }
    public User user { get; set; }
}

public class From
{
    public string username { get; set; }
    public string profile_picture { get; set; }
    public string id { get; set; }
    public string full_name { get; set; }
}

public class Caption
{
    public string created_time { get; set; }
    public string text { get; set; }
    public From from { get; set; }
    public string id { get; set; }
}

public class User2
{
    public string username { get; set; }
    public string website { get; set; }
    public string profile_picture { get; set; }
    public string full_name { get; set; }
    public string bio { get; set; }
    public string id { get; set; }
}

public class Datum
{
    public object attribution { get; set; }
    public List<string> tags { get; set; }
    public string type { get; set; }
    public Location location { get; set; }
    public Comments comments { get; set; }
    public string filter { get; set; }
    public string created_time { get; set; }
    public string link { get; set; }
    public Likes likes { get; set; }
    public Images images { get; set; }
    public List<UsersInPhoto> users_in_photo { get; set; }
    public Caption caption { get; set; }
    public bool user_has_liked { get; set; }
    public string id { get; set; }
    public User2 user { get; set; }
}

public class RootObject
{
    public Pagination pagination { get; set; }
    public Meta meta { get; set; }
    public List<Datum> data { get; set; }
}

您应该然后能够使用JSON.NET反序列化到该结构。

You should then be able to use JSON.NET to deserialize into that structure.

var root = JsonConvert.DeserializeObject<RootObject>(list);

在这一点上只是拉你需要的属性。

At that point just pull the properties you need.

这篇关于使用Json.net Instagram的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆