0

大家好,我正在尝试使用 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);

我得到一个错误服务器返回了一个错误的请求。我认为问题在于我传递参数的方式。人是对象,跟随是行动。

谢谢你的帮助。

4

1 回答 1

2

我发现这篇文章非常有用Using ASP.Net with Facebook's Graph API and OAuth 2.0 Authentication似乎您必须通过将它们重定向到您的一个页面来获取身份验证令牌。

于 2012-09-11T06:11:14.847 回答