Ejemplo n.º 1
0
 /// <param name="state">
 ///     A unique string used to maintain application state between the request and callback.
 ///     When Facebook redirects the user back to your redirect_uri, this parameter's value will be included in the response.
 ///     You should use this to protect against Cross-Site Request Forgery.
 /// </param>
 public string GetRedirectString(string state)
 {
     var requestBuilder = new Helpers.UriBuilder();
     requestBuilder.BaseUrl = FacebookConst.BaseUriAuthorize;
     requestBuilder.Append("client_id", appId);
     requestBuilder.Append("state", state);
     requestBuilder.Append("redirect_uri", redirectCallbackUrl);
     requestBuilder.Append("scope", string.Join(",", rights.Distinct().Select(x => Enums.GetEnumDescription(x)).ToList()));
     return requestBuilder.Uri;
 }
Ejemplo n.º 2
0
        public virtual string Execute(FacebookMethod method)
        {
            requestBuilder = new Helpers.UriBuilder();
            requestBuilder.BaseUrl = String.Format("{0}/{1}", apiUrl.Trim('/'), Enums.GetEnumDescription(method));
            requestBuilder.Append(Parameters);

            if (!String.IsNullOrWhiteSpace(AccessToken))
            {
                requestBuilder.Append("access_token", AccessToken);
            }

            string result = string.Empty;
            try
            {
                var request = HttpWebRequest.Create(requestBuilder.Uri);
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                var response = request.GetResponse();

                using (var responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    result = responseReader.ReadToEnd();
                }
            }
            catch (WebException wex)
            {
                using (var errorResponse = (HttpWebResponse)wex.Response)
                {
                    using (var errReader = new StreamReader(errorResponse.GetResponseStream(), Encoding.UTF8))
                    {
                        result = errReader.ReadToEnd();
                    }
                }
            }
            ErrorParser(result);
            return result;
        }