Пример #1
0
        private void LoginSucceded(string accessToken)
        {
            var fb = new FacebookClient(accessToken);
            var are = new AutoResetEvent(false);
            Dispatcher.BeginInvoke(() => {
                NavigationService.Navigate(new Uri("/Connecting.xaml", UriKind.Relative));
                are.Set();
            });

            fb.GetCompleted += (o, e) => {
                if (e.Error != null) {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();
                var id = (string)result["id"];

                Connection.FacebookUid = id;
                Connection.LoginType = 1;
                are.WaitOne();
                Dispatcher.BeginInvoke(() => Connection.Connect((Page) ((PhoneApplicationFrame)Application.Current.RootVisual).Content));
            };

            fb.GetAsync("me?fields=id");
        }
Пример #2
0
        private object GetFriendsCount()
        {
            var fb = new FacebookClient(txtAccessToken.Text);
            //var fb = new FacebookClient();
            for (int i = 0; i < 100; i++) {
                dynamic result1 = fb.Get(i);
                string id = result1.id;
                string firstName = result1.first_name;
                var lastName = result1.last_name;
            }
            var query = string.Format("SELECT friend_count, name FROM user WHERE uid = me()");
            // var query1 = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0})", "me()");
            fb.GetAsync("fql", new { q = query });
            object returnVal = 0;
            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                  //  Dispatcher.BeginInvoke();// () => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();
                var data = (IList<object>)result["data"];
                foreach (var comment in data.Cast<IDictionary<string, object>>())
                {
                    returnVal = comment["friend_count"];
                    // Dispatcher.BeginInvoke(() => MessageBox.Show(returnVal.ToString()));
                }

            };

            return returnVal;
        }
        private void LoadUserInfo()
        {
            var fb = new FacebookClient(App.AccessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    //ProfileName.Text = "Hi " + (string)result["name"];
                    string myName = String.Format("{0} {1}", (string)result["first_name"], (string)result["last_name"]);
                    Uri myPictureUri = new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", App.FacebookId, "square", App.AccessToken));

                    this.MyImage.Source = new BitmapImage(myPictureUri);
                    this.MyName.Text = myName;
                });
            };

            fb.GetAsync("me");
        }
Пример #4
0
        /// <summary>
        /// Loads the user info.
        /// </summary>
        private void LoadUserInfo()
        {
            var fb = new FacebookClient(App.AccessToken);

            fb.GetCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                    return;
                }

                var result = args.GetResultData<IDictionary<string, object>>();

                Dispatcher.BeginInvoke(() =>
                {
                    FacebookData.Me.Name = String.Format(
                        "{0} {1}",
                        (string)result["first_name"],
                        (string)result["last_name"]);

                    FacebookData.Me.PictureUri = new Uri(String.Format(
                        "https://graph.facebook.com/{0}/picture?type={1}&access_token={2}",
                        App.FacebookId,
                        "square",
                        App.AccessToken));
                });

                fb.GetAsync("me");
            };
        }
Пример #5
0
 // My facebook feed.
 internal void MyProfile()
 {
     GlobalContext.g_UserProfile = new UserProfile();
     var fb = new FacebookClient(GlobalContext.AccessToken);
     fb.GetCompleted +=
         (o, ex) =>
         {
             try
             {
                 var feed = (IDictionary<String, object>)ex.GetResultData();
                 GlobalContext.g_UserProfile.Name = feed["name"].ToString();
                 GlobalContext.g_UserProfile.UserID = feed["id"].ToString();
                 GlobalContext.g_UserProfile.Picture = (String)((IDictionary<String, object>)((IDictionary<String, object>)feed["picture"])["data"])["url"];
                 // GlobalContext.g_UserProfile.Picture = picture.data.url;
                 DBManager.getInstance().saveData(DBManager.DB_Profile, GlobalContext.g_UserProfile);
                 Deployment.Current.Dispatcher.BeginInvoke(delegate(){
                     App42Api.LinkUserFacebookAccount(LinkUserFacebookCallback);
                 });
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.Message);
             }
         };
     var parameters = new Dictionary<String, object>();
     parameters["fields"] = "id,name,picture";
     fb.GetAsync("me", parameters);
 }
        /// <summary>
        /// Makes an asynchronous GET request to the Facebook server.
        /// </summary>
        /// <param name="facebookClient">The facebook client.</param>
        /// <param name="path">The resource path.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The task of the result.</returns>
        public static Task <object> GetTaskAsync(this FacebookClient facebookClient, string path, IDictionary <string, object> parameters)
        {
            Contract.Requires(!(string.IsNullOrEmpty(path) && parameters == 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.GetAsync(path, parameters, tcs);
            }
            catch
            {
                facebookClient.GetCompleted -= handler;
                tcs.TrySetCanceled();
                throw;
            }

            return(tcs.Task);
        }
        public void GetEventsList()
        {
            string fetchStr = string.Format(FetchString, ID);

            RFBClient = new FacebookClient(FBAuthenticationService.AccessToken);
            RFBClient.GetCompleted += new EventHandler<FacebookApiEventArgs>(OnGetEventsCompleted);
            RFBClient.GetAsync(fetchStr);
        }
Пример #8
0
        // My facebook feed.
        public void myProfile()
        {
            var fb = new FacebookClient(_accessToken);
            fb.GetCompleted +=
                (o, ex) =>
                {

                    var feed = (IDictionary<string, object>)ex.GetResultData();
                    var me = feed["picture"] as JsonObject;
                    var pic = me["data"] as JsonObject;
                    string picture = pic["url"].ToString();
                    string name = feed["name"].ToString();
                    string id = feed["id"].ToString();
                    UpdateProfile(name, id, picture);
                    
                };

            var parameters = new Dictionary<string, object>();
            parameters["fields"] = "id,name,picture";
            fb.GetAsync("me", parameters);
        }
Пример #9
0
        public bool ProcessFbOathResult(FacebookOAuthResult oauthResult)
        {
            var resultProcess = false;
            var accessToken = oauthResult.AccessToken;
            App.ViewModel.UserPreference.AccessKey = accessToken;
            var fbS = new FacebookClient(accessToken);

            fbS.GetCompleted += (o, res) =>
                                    {
                                        if (res.Error != null)
                                        {
                                            Dispatcher.BeginInvoke(() =>
                                                                       {
                                                                           gridFBLoggedIn.Visibility =
                                                                               Visibility.Collapsed;
                                                                           FaceBookLoginPage.Visibility =
                                                                               Visibility.Collapsed;
                                                                           LinkButton.Visibility = Visibility.Visible;
                                                                       });

                                            return;
                                        }

                                        var result = (IDictionary<string, object>) res.GetResultData();
                                        App.ViewModel.UserPreference.FbUserId = (string) result["id"];
                                        App.ViewModel.UserPreference.Name = (string) result["name"];
                                        App.ViewModel.LoadData(true);
                                        App.ViewModel.SaveSettings();
                                        Dispatcher.BeginInvoke(() =>
                                                                   {
                                                                       facebookImage.Source =
                                                                           App.ViewModel.UserPreference.UserImage;
                                                                       name.Text = App.ViewModel.UserPreference.Name;
                                                                   });
                                        resultProcess = true;
                                    };

            fbS.GetAsync("me");
            return resultProcess;
        }
Пример #10
0
        public List<string> FriendImages(ActivityItemsViewModel act)
        {
            if (App.ViewModel.UserPreference.AccessKey == null || act.FacebookId == null || act.FacebookId.Equals("") || !App.ViewModel.HasConnection)
                return null;
            var friends = new List<string>();
            var fb = new FacebookClient
            {
                AppId = App.ViewModel.Appid,
                AccessToken = App.ViewModel.UserPreference.AccessKey
            };
            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    return;
                }
                var result = (IDictionary<string, object>)e.GetResultData();
                var data = (IList<object>)result["data"];
                if (data.Count <= 0)
                {
                    return;
                }
                act.FriendsAttending = data.Count;
                for (var i = 0; i < 5; i++)
                {
                    var eventData = ((IDictionary<string, object>)data.ElementAt(i));
                    friends.Add((string)eventData["pic_square"]);
                }

            };
            var query = String.Format("SELECT pic_square FROM user WHERE uid IN"
            + "(SELECT uid2 FROM friend WHERE uid1 = me() AND uid2 IN"
            + "(SELECT uid FROM event_member WHERE eid = {0} "
            + "AND rsvp_status = 'attending'))", act.FacebookId);
             fb.GetAsync("fql", new { q = query });
            return friends;
        }
Пример #11
0
        private void LoginSucceded(string accessToken)
        {
            var fb = new FacebookClient(accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();
                SettingsManager.FacebookActive = true;
                SettingsManager.FacebookToken = accessToken;
                SettingsManager.FacebookId = (string)result["id"];

                Dispatcher.BeginInvoke(() => {
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                });
            };

            fb.GetAsync("me?fields=id");
        }
Пример #12
0
        private void GraphApiPhotos()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }
                count =count+ 8;
                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    int i;
                    panel_count++;
                    Grid grid = new Grid();
                    grid.Name = "Grid" + panel_count;
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    stackPanel1.Children.Add(grid);
                    IList data = (IList)result["data"];
                    for (i = 0; i < data.Count; i++)
                    {
                        IDictionary<string, object> entry = (IDictionary<string, object>)data[i];
                        HubTile hubTile = new HubTile();
                        try
                        {
                            hubTile.Title = (string)entry["name"];
                        }
                        catch
                        {
                            hubTile.Title = "No caption";
                        }
                        //hubTile.Title = "Title";
                        hubTile.Source = new BitmapImage(new Uri((string)entry["picture"]));
                        hubTile.Name = (string)entry["link"];
                        GetComments((string)entry["id"], (string)entry["link"]);
                        hubTile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile_Tap);
                        hubTile.SetValue(Grid.RowProperty, i / 2);
                        hubTile.SetValue(Grid.ColumnProperty, i % 2);
                        grid.Children.Add(hubTile);
                        if (i == data.Count - 1)
                        {
                            int newCount = 0;
                            String imageURL = (string)entry["picture"];
                            String imageURI = imageURL.Replace("https://", "http://");
                            // Application Tile is always the first Tile, even if it is not pinned to Start.
                            ShellTile TileToFind = ShellTile.ActiveTiles.First();
                            // Application should always be found
                            if (TileToFind != null)
                            {
                                // Set the properties to update for the Application Tile.
                                // Empty strings for the text values and URIs will result in the property being cleared.
                                StandardTileData NewTileData = new StandardTileData
                                {
                                    Title = "Fhotos-On-Tiles",
                                    //BackgroundImage = new Uri(imageURL, UriKind.Absolute),
                                    BackgroundImage = new Uri(imageURI),
                                    Count = newCount,
                                    BackTitle = "What is This?",
                                    BackContent = "View your Facebook photos on tiles."
                                };

                                // Update the Application Tile
                                TileToFind.Update(NewTileData);
                            }
                        }
                    }
                    if (i == 8)
                    {
                        Button more_btn = new Button();
                        more_btn.Content = "More...";
                        more_btn.Name = "MoreButton";
                        more_btn.Click += PhoneApplicationPage_Loaded;
                        stackPanel1.Children.Add(more_btn);
                    }

                });
            };

            fb.GetAsync("me/photos?limit=8&offset=" + count + "&fields=name,picture,link");
        }
Пример #13
0
        private void GetComments(String photoID,String URL)
        {
            String comments = "";
            var fb = new FacebookClient(_accessToken);
            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }
                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    int min=2;
                    IList data = (IList)result["data"];
                    if (data.Count < 2)
                        min = data.Count;
                    for (int i = 0; i < min; i++)
                    {
                        IDictionary<string, object> entry = (IDictionary<string, object>)data[i];
                        IDictionary<string, object> from = (IDictionary<string, object>)entry["from"];
                        comments = comments + (string)from["name"] + ": ";
                        comments = comments + (string)entry["message"]+ " ";
                    }
                    if (comments == "")
                        comments = "No comments. Tap to open in facebook and comment there.";
                    HubTile hubtile = (HubTile)this.FindName(URL);
                    hubtile.Message = comments;

                });
            };
            fb.GetAsync(photoID + "/comments?limit=2&fields=from,message");
        }
Пример #14
0
        /// <summary>
        /// Function : To Check whether login successful or not and redirect to landing page
        /// </summary>
        /// <param name="accessToken">Facebook AccessToken</param>
        private void LoginSucceded(string accessToken)
        {
            var fb = new FacebookClient(accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();
                var id = (string)result["id"];

                var url = string.Format("/InfoPage.xaml?access_token={0}&id={1}&expire_time={2}", accessToken, id,_oauthResult.Expires);

                Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri(url, UriKind.Relative)));
            };

            fb.GetAsync("me?fields=id");
        }
 /// <summary>
 /// getting info from facebook depends on query string
 /// <summary>
 public void getFromFB(String url, Action<IDictionary<String, object>> retf)
 {
     FacebookClient _fbClient = new FacebookClient(_accessToken);
     _fbClient.GetCompleted += _fbClient_GetCompleted;
     // async request
     _fbClient.GetAsync(url, null, retf);
 }
 public void GetFriendsList()
 {
     RFBClient = new FacebookClient(FBAuthenticationService.AccessToken);
     RFBClient.GetCompleted += new EventHandler<FacebookApiEventArgs>(OnGetFriendsCompleted);
     RFBClient.GetAsync(FetchString);
 }
Пример #17
0
        /// <summary>
        /// Graph Api interface to get result
        /// </summary>
        public void GraphApi()
        {
            var fb = new FacebookClient(_accessToken);
            fb.GetCompleted += (o, args) =>
                                   {
                                       if (args.Error != null)
                                       {
                                           Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                                           return;
                                       }

                                       var result = (IDictionary<string, object>) args.GetResultData();

                                       Dispatcher.BeginInvoke(() =>
                                                                  {
                                                                      txtAnswer.Text = result.ToString();
                                                                  });
                                   };

            fb.GetAsync("me");
        }
        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.data[0].fql_result_set;
                    dynamic resultForQuery2 = result.data[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.GetAsync("fql", new { q = new[] { query1, query2 } });
        }
        private void kickOffPage()
        {
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            string query = "{\"friendsAll\":\"SELECT uid1, uid2 from friend WHERE uid1 = " + userUid.ToString() + "\", \"friendsLimit\":\"SELECT uid1, uid2 from friend WHERE uid1 = " + userUid.ToString() + " ORDER BY uid2 " + limitArg() + "\", \"friendsoffriends\":\"SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 from #friendsLimit) AND uid2 IN (SELECT uid2 from #friendsAll) AND uid1 < uid2\"}";

            parameters.Add("queries", query);
            parameters.Add("method", "fql.multiquery");

            //Execute
            client = new FacebookClient(fbToken);
            client.GetCompleted += new EventHandler<FacebookApiEventArgs>(client_GetCompleted);
            client.GetAsync(parameters);
        }
Пример #20
0
        private void showFBName(string token)
        {
            var fb = new FacebookClient(token);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Cancelled)
                {
                    // ignore
                }
                else if (e.Error != null)
                {
                    // error occurred
                    this.BeginInvoke(new MethodInvoker(
                                                 () =>
                                                 {
                                                     button5.Visible = true;
                                                     label23.Visible = false;
                                                     label24.Visible = false;
                                                     button6.Visible = false;
                                                    // delete token from settings
                                                     fallyGrab.Properties.Settings.Default.fbToken = "";
                                                     fallyGrab.Properties.Settings.Default.Save();

                                                 }));
                }
                else
                {
                    // the request was completed successfully
                    dynamic result = e.GetResultData();
                    var firstName = result.first_name;
                    var lastName = result["last_name"];

                    // set labels
                    this.BeginInvoke(new MethodInvoker(
                                         () =>
                                         {
                                             label24.Text = firstName + " " + lastName;
                                             label23.Visible = true;
                                             label24.Visible = true;
                                             button6.Visible = true;
                                         }));
                }
            };

            dynamic parameters = new ExpandoObject();
            parameters.fields = "first_name,last_name";

            fb.GetAsync("me", parameters);
        }
        // My facebook feed.
        internal void MyProfile()
        {
            String name = null;
            String id = null;
            var fb = new FacebookClient(GlobalContext.FacebookAccessToken);
            fb.GetCompleted +=
                (o, ex) =>
                {

                    var feed = (IDictionary<String, object>)ex.GetResultData();
                    name = feed["name"].ToString();
                    id = feed["id"].ToString();
                    DBManager.getInstance().saveData(DBManager.DB_Profile, feed);
                    var fbprofiledata = DBManager.getInstance().getDBData(DBManager.DB_Profile);
                    JSONNode jsonObj = JSON.Parse(fbprofiledata);
                    GlobalContext.localUsername = jsonObj["name"].ToString().Split(new char[] { ' ' })[0].Substring(1);
                    GlobalContext.UserFacebookId = id;
                    GlobalContext.GameRoomId = "";
                    JSONNode AuthObj = new JSONClass();
                    AuthObj.Add("FacebookId", id);
                    AuthObj.Add("AccessToken", GlobalContext.FacebookAccessToken);
                    String authString = AuthObj.ToString();
                    Deployment.Current.Dispatcher.BeginInvoke(delegate()
                    {
                        messageGrid.Visibility = Visibility.Visible;
                        WarpClient.GetInstance().Connect(GlobalContext.localUsername, authString);
                    });
                };

            var parameters = new Dictionary<String, object>();
            parameters["fields"] = "id,name";
            fb.GetAsync("me", parameters);
        }
Пример #22
0
        private void GraphApiSample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    ProfileName.Text = "Hi " + (string)result["name"];
                    FirstName.Text = "First Name: " + (string)result["first_name"];
                    FirstName.Text = "Last Name: " + (string)result["last_name"];
                });
            };

            fb.GetAsync("me");
        }
Пример #23
0
        private void FqlSample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();
                var data = (IList<object>)result["data"];

                var count = data.Count;

                // since this is an async callback, make sure to be on the right thread
                // when working with the UI.
                Dispatcher.BeginInvoke(() =>
                {
                    TotalFriends.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()");

            // Note: For windows phone 7, make sure to add [assembly: InternalsVisibleTo("Facebook")] if you are using anonymous objects as parameter.
            fb.GetAsync("fql", new { q = query });
        }
Пример #24
0
        private void LoginSucceded(string accessToken)
        {
            client.AccessToken = accessToken;

            client.GetAsync("me");
        }
Пример #25
0
        /// <summary>
        /// Load Facebook information of the user
        /// </summary>
        public void LoadUserInformation()
        {
            // available picture types: square (50x50), small (50xvariable height), large (about 200x variable height) (all size in pixels)
            string profilePictureUrl = string.Format(
                "https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", _userId, "square", _accessToken);
            // load profile picture
            picProfile.Source = new BitmapImage(new Uri(profilePictureUrl));

            var fb = new FacebookClient(_accessToken);
            fb.GetCompleted += (o, e) =>
                                   {
                                       if (e.Error != null)
                                       {
                                           Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                                           return;
                                       }

                                       var result = (IDictionary<string, object>) e.GetResultData();
                                       Dispatcher.BeginInvoke(() =>
                                                                  {
                                                                      ProfileName.Text = "Hi " + (string) result["name"];
                                                                      FirstName.Text = "First Name: " +
                                                                                       (string) result["first_name"];
                                                                      FirstName.Text = "Last Name: " +
                                                                                       (string) result["last_name"];
                                                                  });
                                   };

            // get user information
            fb.GetAsync("me");
        }
        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 = (IDictionary<string, object>)e.GetResultData();
                    var data = (IList<object>)result["data"];

                    var count = data.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.GetAsync("fql", new { q = query });
        }
Пример #27
0
        /// <summary>
        /// Fql Sample to get Result
        /// </summary>
        public void FqlSample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, args) =>
                                   {
                                       if (args.Error != null)
                                       {
                                           Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                                           return;
                                       }

                                       var result = (IDictionary<string, object>) args.GetResultData();
                                       var data = (IList<object>) result["data"];

                                       // since this is an async callback, make sure to be on the right thread
                                       // when working with the UI.
                                       Dispatcher.BeginInvoke(() =>
                                                                  {
                                                                      txtAnswer.Text = data.ToString();
                                                                  });
                                   };

            // 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()");
            fb.GetAsync("fql", new {q = query});
        }
Пример #28
0
        private void Facebook()
        {
            Action facebookLogin = async () =>
            {
                try
                {
                    base.ShowHeaderLoader();
                    EmailTextBoxIsEnabled = false;

                    FacebookSession facebookSession = await DrumbleApp.Shared.Infrastructure.Helpers.Facebook.Authenticate();

                    var fb = new FacebookClient(facebookSession.AccessToken);

                    fb.GetCompleted += (o, e) =>
                    {
                        if (e.Error != null)
                        {
                            Action facebookError = () =>
                            {
                                base.ShowPopup(CustomPopupMessageType.Error, AppResources.RegisterFacebookErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);

                                EmailTextBoxIsEnabled = true;
                                base.HideHeaderLoader();
                            };

                            DispatcherHelper.CheckBeginInvokeOnUI(facebookError);

                            return;
                        }

                        Action getFacebookDetails = async () =>
                        {
                            var result = (IDictionary<string, object>)e.GetResultData();

                            if (user == null)
                                user = new User();

                            user.FacebookInfo = new FacebookInfo(facebookSession.AccessToken, facebookSession.FacebookId);

                            cancellationTokenSource = new CancellationTokenSource();

                            user = await DrumbleApi.LoginFacebook(cancellationTokenSource.Token, user);

                            if (isInAppLogin)
                                UnitOfWork.UserRepository.Update(user);
                            else
                                UnitOfWork.UserRepository.Insert(user);
                            UnitOfWork.Save();

                            base.HideHeaderLoader();
                            EmailTextBoxIsEnabled = true;

                            if (isInAppLogin)
                                NavigationService.NavigateTo("/Views/Profile.xaml");
                            else
                                NavigationService.NavigateTo("/Views/SplashScreen.xaml?pagestate=facebooklogin");
                        };
                        DispatcherHelper.CheckBeginInvokeOnUI(getFacebookDetails);
                    };

                    fb.GetAsync("me");
                }
                catch (Exception e)
                {
                    string exception = e.Message;

                    EmailTextBoxIsEnabled = true;
                    base.HideHeaderLoader();
                }
            };

            DispatcherHelper.CheckBeginInvokeOnUI(facebookLogin);
        }
        private void GraphApiAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            // make sure to add the appropriate event handler
            // before calling the async methods.
            // GetCompleted     => GetAsync
            // PostCompleted    => PostAsync
            // DeleteCompleted  => DeleteAsync
            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.
                    // For this example, we know that it is IDictionary<string,object>.
                    var result = (IDictionary<string, object>)e.GetResultData();

                    var firstName = (string)result["first_name"];
                    var lastName = (string)result["last_name"];

                    // since this is an async callback, make sure to be on the right thread
                    // when working with the UI.
                    this.BeginInvoke(new MethodInvoker(
                                         () =>
                                         {
                                             lblFirstName.Text = "First Name: " + firstName;
                                         }));
                }
            };

            // additional parameters can be passed and
            // must be assignable from IDictionary<string, object>
            var parameters = new Dictionary<string, object>();
            parameters["fields"] = "first_name,last_name";

            fb.GetAsync("me", parameters);
        }
        private void LegacyRestApiAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            // make sure to add the appropriate event handler
            // before calling the async methods.
            // GetCompleted     => GetAsync
            // PostCompleted    => PostAsync
            // DeleteCompleted  => DeleteAsync
            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();

                    // or you could also use the generic version;
                    bool isFan = e.GetResultData<bool>();

                    // since this is an async callback, make sure to be on the right thread
                    // when working with the UI.
                    this.BeginInvoke(new MethodInvoker(
                                         () =>
                                         {
                                             chkCSharpSdkFan.Checked = isFan;
                                         }));
                }
            };

            dynamic parameters = new ExpandoObject();
            // any parameter that has "method" automatically is treated as rest api.
            parameters.method = "pages.isFan";
            parameters.page_id = "471653766213114";  // id of http://www.facebook.com/csharpsdk official page

            // for rest api only, parameters is enough
            // the rest method is determined by parameters.method
            fb.GetAsync(parameters);
        }
Пример #31
0
        private void loginSucceeded(FacebookOAuthResult authResult)
        {
            TitleBox.Visibility = Visibility.Visible;
            FacebookLoginBrowser.Visibility = Visibility.Collapsed;
            InfoBox.Visibility = Visibility.Visible;

            var fb = new FacebookClient(authResult.AccessToken);

            fb.GetCompleted +=
                (o, e) =>
                {
                    if (e.Error == null)
                    {
                        var result = (IDictionary<string, object>)e.GetResultData();
                        Dispatcher.BeginInvoke(() => InfoBox.ItemsSource = result);
                    }
                    else
                    {
                        MessageBox.Show(e.Error.Message);
                    }
                };

            fb.GetAsync("/me");
        }
        private void LoadUserInfo()
        {


            var fb = new FacebookClient(fftoken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    var profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}&width=150&height=150", ffid, "square", fftoken);

                    this.user_image.Source = new BitmapImage(new Uri(profilePictureUrl));
                    //this.MyName.Text = String.Format("{0} {1}", (string)result["first_name"], (string)result["last_name"]);
                });
            };

            fb.GetAsync("me");
        }