ExchangeCodeForAccessTokenAsync() public method

Exchange code for access token asynchronously.
public ExchangeCodeForAccessTokenAsync ( string code ) : void
code string /// The code. ///
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Exchange code for access token asynchronously.
        /// </summary>
        /// <param name="facebookOAuthClient">The Facebook OAuth Client.</param>
        /// <param name="code">The code.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The task of the result.</returns>
        public static Task <object> ExchangeCodeForAccessTokenTaskAsync(this FacebookOAuthClient facebookOAuthClient, string code, IDictionary <string, object> parameters)
        {
            var tcs = FacebookClientTaskExtensions.CreateSource <object>(null);

            EventHandler <FacebookApiEventArgs> handler = null;

            handler = (sender, e) => FacebookClientTaskExtensions.TransferCompletionToTask <object>(tcs, e, () => e.GetResultData(), () => facebookOAuthClient.ExchangeCodeForAccessTokenCompleted -= handler);

            facebookOAuthClient.GetApplicationAccessTokenCompleted += handler;

            try
            {
                facebookOAuthClient.ExchangeCodeForAccessTokenAsync(code, parameters, tcs);
            }
            catch
            {
                facebookOAuthClient.ExchangeCodeForAccessTokenCompleted -= handler;
                tcs.TrySetCanceled();
                throw;
            }

            return(tcs.Task);
        }