1

我正在使用 Instasharp 获取用户信息。它工作正常。但需要的是用户发布的图片,用户媒体。

要检索我使用的用户提要:

var result = users.Feed("self");

我一直在尝试最近但它正在抛出和错误:

                authInfo.Access_Token = ConfigurationManager.AppSettings["instagramAccessToken"];

            var users = new InstaSharp.Endpoints.Users.Authenticated(config, authInfo);
            var result = users.Feed("self"); 

错误:NullReferenceException。没有为对象的实例定义对象引用

我一直试图找到如何使用 Instasharp 执行此操作的答案,但没有成功。你们中是否有人有这个答案或一个很好的链接来展示如何做到这一点?

提前致谢

4

1 回答 1

1

I gave up due my deadline, so I had to consume the JSON.

Get the JSON

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.instagram.com/v1/users/xxxxxx/media/recent?access_token=" + ConfigurationManager.AppSettings["instagramAccessToken"]);
        request.Method = "GET";
        String json = String.Empty;
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            json = reader.ReadToEnd();
            reader.Close();
            dataStream.Close();
        }

Read it and insert in a database, using Linq to SQL:

            dynamic dyn = JsonConvert.DeserializeObject(json);
        foreach (var data in dyn.data)
        {
            RES_PostInstagram reg = new RES_PostInstagram();
            reg.filter = data.filter;
            reg.idPost = data.id;
            reg.image = data.images.standard_resolution.url;
            reg.link = data.link;
            reg.publicar = true;
            reg.thumbnail = data.images.thumbnail.url;
            reg.type = data.type;
            reg.created_time = this.UnixTimeStampToDateTime((double)data.created_time);

            if (data.caption != null)
                reg.caption = data.caption.text;

            foreach (string tag in data.tags)
                reg.tags += tag + ", ";

            // se o post nao existir no banco inserir
            RES_PostInstagram existe = (from p in this.ctx.RES_PostInstagrams
                                            where p.idPost == reg.idPost
                                            select p).FirstOrDefault();
            if (existe == null)
            {
                this.ctx.RES_PostInstagrams.InsertOnSubmit(reg);
                this.ctx.SubmitChanges();
            }

        } 

Convert Unix Timestamp to DateTime:

        public  DateTime UnixTimeStampToDateTime(double unixTimeStamp)
    {
        // Unix timestamp is seconds past epoch
        System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
        return dtDateTime;
    }
于 2013-11-07T02:26:36.340 回答