Instagram订阅408请求超时2秒后 [英] Instagram Subscription 408 Request Timeout after 2 seconds

查看:144
本文介绍了Instagram订阅408请求超时2秒后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用instagram订阅功能为我的MVC网站的用户创建一种与instagram同步"机制.现在,我已经正确设置了所有内容,就像它们在其api页上所描述的一样:

I am currently trying to create a 'sync with instagram' mechanism for the users of my MVC website using the instagram subscription feature. Now I have everything set up correctly like they are describing on their api page:

  • 我将用户定向到他们的授权页面,成功获得授权.
  • 我为回调方法创建了GET和POST方法.用于测试是否存在的GET与所描述的参数(hub.mode = subscribe& hub.challenge = test& hub.verify_token = mytoken)一起使用时会成功返回挑战,并且我使用ngrok将其暴露给了互联网(有效)也是)
  • 然后,我尝试订阅一个用户,该用户在2秒后立即崩溃,并且请求超时为408.永远不会发生对回调URL的GET请求.
  • I direct the user to their authorization page, getting the authorization successfully.
  • I created a GET and a POST method for the callback method. The GET to test if it is there works with the described parameters (hub.mode=subscribe&hub.challenge=test&hub.verify_token=mytoken) that returns the challenge when successful and I exposed it to the internet using ngrok (which works too)
  • Then I am trying to subscribe to the user which crashes immediately after 2 seconds with a 408 Request timeout. The GET request to the callback url never happens.

我还试图稍微更改我在那个帖子请求中发送的instagram,如果我更改了一件东西,我得到了一个不好的请求,而不是超时. 我也尝试过创建自己的网络客户端,以使网络请求超时,但是没有运气.

I also tried to slightly change what I am sending instagram in that post request, if I change one thing I am getting a bad request instead of the timeout. I've also tried to create my own webclient to up the web requests timeout with no luck.

有人对我做错了什么有什么想法,或者从哪里获得关于真正失败了的更多信息的想法? instagram文档非常缺乏.

Does anyone have an idea on what I am doing wrong or where to get more information on what really failed? The instagram documentation is pretty lacking.

以下是与408崩溃的代码:

Here is the code that crashes with the 408:

        NameValueCollection parameters = new NameValueCollection();
        parameters.Add("client_id", "SECRET"); 
        parameters.Add("client_secret", "SECRET");
        parameters.Add("object", "user");
        parameters.Add("aspect", "media");
        parameters.Add("verify_token", VerifyToken);
        parameters.Add("callback_url", new Uri(baseUri, "api/manage/instagramSubscription").AbsoluteUri);

        var client = new WebClient();
        var result = client.UploadValues("https://api.instagram.com/v1/subscriptions/", "POST", parameters);

解决问题的解决方案

现在问题就像在tompec的避免ngrok的解决方案中一样.我试图与instagram联络,以了解为什么ngrok无法正常运作但一如既往地没有答案.我切换到Azure函数,以便能够快速测试instagram进行的回调.在此过程中进行了一些修改,但现在可以了.我必须重写该调用的代码,因为instagram只接受此调用的表单数据.

Now the problem was like in tompec's solution to avoid ngrok. I have tried to reach out to instagram on why ngrok does not work but no answer as always. I switched to an Azure Function to be able to quickly test the callback that instagram makes. had a few hickups along the way but now it works. I had to rewrite the code for the call though because instagram only accepts form data for this call.

var encoding = new ASCIIEncoding();
        var postData = "client_id=YOURCLIENTID";  
        postData += "&client_secret=YOURSECRET"; 
        postData += ("&object=user");
        postData += ("&aspect=media");
        postData += ("&verify_token=" + VerifyToken);
        postData += ("&callback_url=" + baseUri.AbsoluteUri);
        byte[] data = encoding.GetBytes(postData);

        var myRequest =
            (HttpWebRequest)WebRequest.Create("https://api.instagram.com/v1/subscriptions/");
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = data.Length;
        using (var newStream = myRequest.GetRequestStream())
        {
            newStream.Write(data, 0, data.Length);
        }

        InstagramSubscriptionResponseViewModel instaResponse = null;
        using (var response = myRequest.GetResponse())
        {
            var responseStream = response.GetResponseStream();
            if (responseStream != null)
            {
                using (var responseReader = new StreamReader(responseStream))
                {
                    var result = responseReader.ReadToEnd();

                    // do whatever you want

                }

            }
        }

推荐答案

这是因为ngrok.我不知道为什么,但是我遇到了同样的问题,并且在将文件上传到网络服务器后,它可以正常工作.

It is because of ngrok. I don't know why, but I had the same problem and after uploading the files on a web server, it worked.

这篇关于Instagram订阅408请求超时2秒后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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