如何从 Instagram RealTime API 更新中读取 Json 数据

How to read Json data from Instagram RealTime API updates

我正在尝试使用 Instagram RealTime API 在有人发布带有特定标签的图片时获取更新,我已按照所有步骤操作,但我无法阅读 json 发送到我的回调的数据 url。根据 instagram 的文档:

When someone posts a new photo and it triggers an update of one of your subscriptions, we make a POST request to the callback URL that you defined in the subscription. The post body contains a raw text JSON body with update objects.

我正在使用 C# 和 MVC 5,这是我读取 "raw text JSON body" 的代码,请注意,我将 json 字符串保存在文本文件中。

[HttpPost]
public HttpStatusCodeResult Receive()
{
    string json;

    using (var reader = new StreamReader(Request.InputStream))
    {
        json = reader.ReadToEnd();
    }

    File.WriteAllText(Path.Combine(Server.MapPath("~/"), "test.txt"), json);

    return new HttpStatusCodeResult(200);
}

问题是,当我收到请求时,文件已创建,但始终为空。我的代码有问题吗?会不会是 Instagram 的 API 有问题?如果能提供一些帮助,我将不胜感激。

找到了!只需将 InputStream 位置设置为零即可!