Exemple #1
0
        /// <summary>
        /// Makes a async request to the Facebook server.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="httpMethod">
        /// The http Method.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <param name="userToken">
        /// The user Token.
        /// </param>
        public virtual void ApiAsync(string path, IDictionary <string, object> parameters, HttpMethod httpMethod, FacebookAsyncCallback callback, object userToken)
        {
            var facebookClient = GetFacebookClient();

            if (callback != null)
            {
                switch (httpMethod)
                {
                case HttpMethod.Get:
                    facebookClient.GetCompleted += (o, e) => callback(new FacebookAsyncResult(e.GetResultData(), e.UserState, null, false, true, e.Error as FacebookApiException));
                    break;

                case HttpMethod.Post:
                    facebookClient.PostCompleted += (o, e) => callback(new FacebookAsyncResult(e.GetResultData(), e.UserState, null, false, true, e.Error as FacebookApiException));
                    break;

                case HttpMethod.Delete:
                    facebookClient.DeleteCompleted += (o, e) => callback(new FacebookAsyncResult(e.GetResultData(), e.UserState, null, false, true, e.Error as FacebookApiException));
                    break;

                default:
                    throw new ArgumentOutOfRangeException("httpMethod");
                }
            }

            facebookClient.ApiAsync(path, FacebookWebClient.AddReturnSslResourceIfRequired(parameters, IsSecureConnection), httpMethod, userToken);
        }
Exemple #2
0
 /// <summary>
 /// Makes a async request to the Facebook server.
 /// </summary>
 /// <param name="path">
 /// The path.
 /// </param>
 /// <param name="parameters">
 /// The parameters.
 /// </param>
 /// <param name="httpMethod">
 /// The http Method.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="state">
 /// The state.
 /// </param>
 public virtual void ApiAsync <T>(string path, IDictionary <string, object> parameters, HttpMethod httpMethod, FacebookAsyncCallback <T> callback, object state)
 {
     ApiAsync(
         path,
         FacebookWebClient.AddReturnSslResourceIfRequired(parameters, IsSecureConnection),
         httpMethod,
         ar =>
     {
         if (callback != null)
         {
             callback(new FacebookAsyncResult <T>(ar.Result, ar.AsyncState, ar.AsyncWaitHandle, ar.CompletedSynchronously, ar.IsCompleted, ar.Error));
         }
     },
         state);
 }
Exemple #3
0
        /// <summary>
        /// Makes a request to the Facebook server.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="resultType">
        /// The result type.
        /// </param>
        /// <param name="httpMethod">
        /// The http method.
        /// </param>
        /// <exception cref="Facebook.FacebookApiException"/>
        /// <returns>
        /// The json result.
        /// </returns>
        public virtual object Api(string path, IDictionary <string, object> parameters, Type resultType, HttpMethod httpMethod)
        {
            try
            {
                var facebookClient = GetFacebookClient();

                return(facebookClient.Api(path, FacebookWebClient.AddReturnSslResourceIfRequired(parameters, IsSecureConnection), httpMethod, resultType));
            }
            catch (FacebookOAuthException)
            {
                try
                {
                    _request.DeleteAuthCookie();
                }
                catch { }
                throw;
            }
        }