/// <summary>
        /// Executes a FQL multiquery asynchronously.
        /// </summary>
        /// <param name="facebookClient">The facebook client.</param>
        /// <param name="fql">The FQL query.</param>
        /// <returns>The task of the result.</returns>
        public static Task <object> QueryTaskAsync(this FacebookClient facebookClient, params string[] fql)
        {
            Contract.Requires(fql != null);

            var tcs = CreateSource <object>(null);

            EventHandler <FacebookApiEventArgs> handler = null;

            handler = (sender, e) => TransferCompletionToTask <object>(tcs, e, () => e.GetResultData(), () => facebookClient.GetCompleted -= handler);

            facebookClient.GetCompleted += handler;

            try
            {
                facebookClient.QueryAsync(fql, tcs);
            }
            catch
            {
                facebookClient.GetCompleted -= handler;
                tcs.TrySetCanceled();
                throw;
            }

            return(tcs.Task);
        }
Ejemplo n.º 2
0
 private void btnGetFriendsList_Click(object sender, RoutedEventArgs e)
 {
     FacebookClient client = new FacebookClient(Token());
     string fqlFriendsList = "SELECT uid2 FROM friend where uid1=me()";
     client.GetCompleted += new EventHandler<FacebookApiEventArgs>(client_GetCompleted);
     client.QueryAsync(fqlFriendsList, Token());
 }
Ejemplo n.º 3
0
        public void Run()
        {
            //1. Prepare API
            string fqlQuery = "SELECT uid, name, pic_big, pic_square, profile_url " +
                "FROM user WHERE uid=" + userUid.ToString();

            //2. Add Async Event Handler
            FacebookClient client = new FacebookClient(fbToken);
            client.GetCompleted += new EventHandler<FacebookApiEventArgs>(client_GetCompleted);

            //3. Execute
            client.QueryAsync(fqlQuery);
        }
        private void FqlMultiQueryAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            // since FQL multi-query is internally a GET request,
            // make sure to add the GET event handler.
            fb.GetCompleted += (o, e) =>
            {
                // incase you support cancellation, make sure to check
                // e.Cancelled property first even before checking (e.Error!=null).
                if (e.Cancelled)
                {
                    // for this example, we can ignore as we don't allow this
                    // example to be cancelled.

                    // you can check e.Error for reasons behind the cancellation.
                    var cancellationError = e.Error;
                }
                else if (e.Error != null)
                {
                    // error occurred
                    this.BeginInvoke(new MethodInvoker(
                                                 () =>
                                                 {
                                                     //MessageBox.Show(e.Error.Message);
                                                 }));
                }
                else
                {
                    // the request was completed successfully

                    // now we can either cast it to IDictionary<string, object> or IList<object>
                    // depending on the type. or we could use dynamic.
                    dynamic result = e.GetResultData();

                    dynamic resultForQuery1 = result[0].fql_result_set;
                    dynamic resultForQuery2 = result[1].fql_result_set;

                    var uid = resultForQuery1[0].uid;

                    this.BeginInvoke(new MethodInvoker(
                                         () =>
                                         {
                                             // make sure to be on the right thread when working with ui.
                                         }));
                }
            };

            var query1 = "SELECT uid FROM user WHERE uid=me()";
            var query2 = "SELECT profile_url FROM user WHERE uid=me()";

            // call the Query or QueryAsync method to execute a single fql query.
            // if there is more than one query Query/QueryAsync method will automatically
            // treat it as multi-query.
            fb.QueryAsync(new[] { query1, query2 });
        }
        private void FqlAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            // since FQL is internally a GET request,
            // make sure to add the GET event handler.
            fb.GetCompleted += (o, e) =>
            {
                // incase you support cancellation, make sure to check
                // e.Cancelled property first even before checking (e.Error!=null).
                if (e.Cancelled)
                {
                    // for this example, we can ignore as we don't allow this
                    // example to be cancelled.

                    // you can check e.Error for reasons behind the cancellation.
                    var cancellationError = e.Error;
                }
                else if (e.Error != null)
                {
                    // error occurred
                    this.BeginInvoke(new MethodInvoker(
                                                 () =>
                                                 {
                                                     //MessageBox.Show(e.Error.Message);
                                                 }));
                }
                else
                {
                    // the request was completed successfully

                    // now we can either cast it to IDictionary<string, object> or IList<object>
                    // depending on the type. or we could use dynamic.
                    var result = (IList<object>)e.GetResultData();

                    var count = result.Count;

                    // since this is an async callback, make sure to be on the right thread
                    // when working with the UI.
                    this.BeginInvoke(new MethodInvoker(
                                         () =>
                                         {
                                             lblTotalFriends.Text = string.Format("You have {0} friend(s).", count);
                                         }));
                }
            };

            // query to get all the friends
            var query = string.Format("SELECT uid,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0})", "me()");

            // call the Query or QueryAsync method to execute a single fql query.
            fb.QueryAsync(query);
        }
Ejemplo n.º 6
0
        public void Run()
        {
            //1. Prepare API
            string query0 = "SELECT uid2 FROM friend where uid1=me()";
            string query1 =
                "SELECT uid, name, pic_big ,pic_square, profile_url, profile_update_time, is_app_user, wall_count, " +
                "birthday_date, online_presence, relationship_status, significant_other_id, sex, status, website " +
                "FROM user WHERE uid IN (SELECT uid2 FROM #query0)";
            string query2 = "SELECT uid,time,message FROM status WHERE uid IN (SELECT uid2 FROM friend WHERE uid1= me())";
            string[] fqlMultiQuery = { query0, query1, query2 };

            //2. Add Async Event Handler
            FacebookClient client = new FacebookClient(fbToken);
            client.GetCompleted += new EventHandler<FacebookApiEventArgs>(client_GetCompleted);

            //3. Execute
            client.QueryAsync(fqlMultiQuery);
        }