使用 c# 和 HttpWebRequest 发布打开图形操作



大家好,我正在尝试使用HttpWebRequest方法将打开的图形操作发布到Facebook。

这是我的请求方法

public static string RequestUrl(string action, String HTTPMETHOD, dynamic postdata = null)
    {
        string results = "";
        try
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
            if (HTTPMETHOD == "GET")
            {
                req.Method = WebRequestMethods.Http.Get;
            }
            else if (HTTPMETHOD == "POST")
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                req.Method = WebRequestMethods.Http.Post;
                byte[] data = encoding.GetBytes(postdata.sneaqer);
                req.ContentLength = data.Length;
                req.ContentType = "application/x-www-form-urlencoded";
                Stream newStream = req.GetRequestStream();
                newStream.Write(data, 0, data.Length);
                newStream.Close();
            }
            else if (HTTPMETHOD == "DELETE")
            {
                req.Method = "DELETE";
                ASCIIEncoding encoding = new ASCIIEncoding();
            }
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(resp.GetResponseStream());
            results = sr.ReadToEnd();
            sr.Close();
        }
        catch (Exception ex)
        {
            Error.Log("ERROR: Common.cs requestUrl() " + ex.Message + " " + action);
        }
        return results;
    }

这是我到目前为止尝试过的

var url = "https://graph.facebook.com/" + personFacebookUserId + "/verbNamespace:follow";
    dynamic parameters = new System.Dynamic.ExpandoObject();
    parameters.person = "http:" + Configuration.getConfigValue("SiteUrl") + "OG/OpenGraphAction.aspx?type=follow&facebookProfilePicture=" + friendFacebookUserId;
    string result = Common.RequestUrl(url, "POST", parameters);

我收到一个错误服务器返回了一个错误的请求。我认为问题在于我传入参数的方式。人是客体,跟随就是行动。

感谢您的任何帮助。

我发现这家伙的文章非常有用 将 ASP.Net 与Facebook的图形API和OAuth 2.0身份验证一起使用 似乎您必须通过让它们重定向到您的一个页面来获取身份验证令牌。

最新更新