Beispiel #1
0
        public async Task <ActionResult> FB_PicturePages()
        {
            var access_token    = HttpContext.Items["access_token"].ToString();
            var appsecret_proof = access_token.GenerateAppSecretProof();

            var facebookClient = new FacebookClient();

            var myInfo = await facebookClient.GetAsync <dynamic>(
                access_token, "me", "fields=name");

            var pictures = await facebookClient.GetAsync <dynamic>(
                access_token, $"{myInfo.id}/photos/uploaded", "fields=created_time,album,source");

            var pictureList = new List <FacebookPictureViewModel>();

            foreach (dynamic picture in pictures.data)
            {
                var facebookPicture = new FacebookPictureViewModel
                {
                    Id          = picture.id,
                    PictureURL  = picture.source,
                    CreatedTime = picture.created_time
                                  // Albums shoud implement :D
                };

                pictureList.Add(facebookPicture);
            }


            return(PartialView(pictureList));
        }
Beispiel #2
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, args) =>
            {
                if (args.Error == null)
                {
                    _me = (IDictionary <string, object>)args.GetResultData();

                    Dispatcher.BeginInvoke(
                        () =>
                    {
                        LoadProfilePicture();
                        ProfileName.Text = "Hi " + _me["name"];
                        FirstName.Text   = "First Name: " + _me["first_name"];
                        LastName.Text    = "Last Name: " + _me["last_name"];
                    });
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                }
            };

            // do a GetAsync me in order to get basic details of the user.
            fb.GetAsync("me");
        }
Beispiel #3
0
        private void GraphApiSample(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();

                Dispatcher.BeginInvoke(() =>
                {
                    tFbName.Text = "Logged in as: " + (string)result["name"];
                    IsolatedStorageSettings.ApplicationSettings["firstname"] = (string)result["first_name"];
                    IsolatedStorageSettings.ApplicationSettings["lastname"]  = (string)result["last_name"];
                    IsolatedStorageSettings.ApplicationSettings["email"]     = (string)result["email"];
                    IsolatedStorageSettings.ApplicationSettings["fbid"]      = (string)result["id"];
                    IsolatedStorageSettings.ApplicationSettings.Save();
                    heroku.AddUser((string)result["id"], (string)result["email"], (string)result["first_name"], (string)result["last_name"]);
                });
            };

            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");
        }
Beispiel #5
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 });
        }
Beispiel #6
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();
                var id     = (string)result["id"];

                var url = string.Format("/FacebookPages/FacebookInfoPage.xaml?access_token={0}&id={1}", accessToken, id);

                Dispatcher.BeginInvoke(() => {
                    ViewModelLocator.UserStatic.FacebookId    = id;
                    ViewModelLocator.UserStatic.FacebookToken = accessToken;
                    ViewModelLocator.UserStatic.GetFBUserInfo();
                    ViewModelLocator.MainStatic.Loading = true;
                    ViewModelLocator.UserStatic.GetPolicemanAchieve();

                    NavigationService.GoBack();
                    //NavigationService.Navigate(new Uri("/PanoramaPage.xaml", UriKind.Relative));
                });
            };

            fb.GetAsync("me");
        }
Beispiel #7
0
        public string GetRsvp(ActivityItemsViewModel act)
        {
            if (App.ViewModel.UserPreference.AccessKey == null || act.FacebookId == null || act.FacebookId.Equals("") || !App.ViewModel.HasConnection)
            {
                return(null);
            }
            string status = null;
            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)
                {
                    status = "not_replied";
                    return;
                }
                var eventData = ((IDictionary <string, object>)data.ElementAt(0));
                status = (string)eventData["rsvp_status"];
            };
            var query = String.Format("SELECT rsvp_status FROM event_member  WHERE eid = {0} AND uid = me()", act.FacebookId);

            fb.GetAsync("fql", new { q = query });
            return(status);
        }
Beispiel #8
0
        // 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);
        }
    private void FBLoginSucceded(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"];
            userIdentity.FBAccessToken = accessToken;
            userIdentity.FBID          = id;
            facebookData["Name"]       = result["first_name"];
            facebookData["Surname"]    = result["last_name"];
            facebookData["Email"]      = result["email"];
            facebookData["Birthday"]   = DateTime.Parse((string)result["birthday"]);
            facebookData["Country"]    = result["locale"];
            Dispatcher.BeginInvoke(() =>
            {
                BitmapImage profilePicture     = new BitmapImage(new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", id, "square", accessToken)));
                facebookData["ProfilePicture"] = profilePicture;
                userIdentity.FBData            = facebookData;
                userIdentity.ProfilePicture    = profilePicture;
                ARLoginOrRegister();
            });
        };
        fb.GetAsync("me");
    }
Beispiel #10
0
        public async Task <ActionResult> FB_PostPages()
        {
            var access_token    = HttpContext.Items["access_token"].ToString();
            var appsecret_proof = access_token.GenerateAppSecretProof();

            var facebookClient = new FacebookClient();

            var posts = await facebookClient.GetAsync <dynamic>(
                access_token, "me", "fields=posts{description,caption,message,story,link,name,created_time,picture}");

            var postList = new List <FacebookPostViewModel>();

            foreach (dynamic post in posts.posts.data)
            {
                var facebookPost = new FacebookPostViewModel
                {
                    Id          = post.id,
                    Name        = post.name,
                    CreatedTime = post.created_time,
                    Message     = post.message,
                    Description = post.description,
                    Story       = post.story,
                    Caption     = post.caption,
                    Link        = post.link,
                    PictureURL  = post.picture,
                };
                postList.Add(facebookPost);
            }

            return(PartialView(postList));
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public void GetFBUserInfo()
        {
            var fb = new FacebookClient(FacebookToken);

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

                var result = (IDictionary <string, object>)e.GetResultData();
                Dictionary <string, object> d_result = new Dictionary <string, object>();
                foreach (var item in result)
                {
                    d_result.Add(item.Key, item.Value.ToString());
                }
                ;
                d_result.Add("fb_id", FacebookId);
                d_result.Add("fb_token", FacebookToken);

                SaveToIsolatedStorage(d_result, FacebookId);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    LoadUserData(d_result);
                });
            };
            fb.GetAsync("me");
        }
        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("/Pages/FacebookInfoPage.xaml?access_token={0}&id={1}", accessToken, id);

                Dispatcher.BeginInvoke(() =>
                {
                    ViewModelLocator.MainStatic.User               = new UserViewModel();
                    ViewModelLocator.MainStatic.User.FacebookId    = id;
                    ViewModelLocator.MainStatic.User.FacebookToken = accessToken;
                    ViewModelLocator.MainStatic.User.IsLogged      = true;
                    GraphApiSample();
                });
            };

            fb.GetAsync("me?fields=id");
        }
Beispiel #14
0
        private async Task <bool> LoadToCollectionAsync(FacebookCursor cursor = null, FacebookCursor.Direction direction = FacebookCursor.Direction.None)
        {
            try
            {
                var response = await _fbClient.GetAsync(_query, _token, cursor, direction);

                var results = response["data"];

                if (!results.Any())
                {
                    return(false);
                }

                foreach (var result in results)
                {
                    var mappedResult = Mapper(result);
                    Add(mappedResult);
                }

                var newCursor = response["paging"]["cursors"];
                var before    = newCursor["before"]?.ToString();
                var after     = newCursor["after"]?.ToString();
                Cursor = new FacebookCursor(before, after);

                return(true);
            }
            catch (Exception ex)
            {
                throw new FacebookCollectionException($"There was a problem loading additional items to Facebook collection {typeof(T)}", ex);
            }
        }
Beispiel #15
0
        private void GraphApiExample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error == null)
                {
                    // make sure to reference Microsoft.CSharp if you want to use dynamic
                    dynamic me = e.GetResultData();

                    Dispatcher.BeginInvoke(
                        () =>
                    {
                        picProfile.Source = new BitmapImage(new Uri(string.Format("https://graph.facebook.com/{0}/picture", me.id)));

                        ProfileName.Text = "Hi " + me.name;
                        FirstName.Text   = "First Name: " + me.first_name;
                        LastName.Text    = "Last Name: " + me.last_name;
                    });
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                }
            };
            fb.GetAsync("me");
        }
        public void GetEventsList()
        {
            string fetchStr = string.Format(FetchString, ID);

            RFBClient = new FacebookClient(FBAuthenticationService.AccessToken);
            RFBClient.GetCompleted += new EventHandler <FacebookApiEventArgs>(OnGetEventsCompleted);
            RFBClient.GetAsync(fetchStr);
        }
Beispiel #17
0
 /// <summary>
 /// Gets a user access token that lasts around 60 days.
 /// </summary>
 /// <source>https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/#get-a-long-lived-page-access-token</source>
 /// <returns>JObject with extended access token</returns>
 public async Task <JObject> RequestExtendAccessToken()
 {
     return(await FacebookClient.GetAsync(
                $"/oauth/access_token" +
                $"?grant_type=fb_exchange_token" +
                $"&client_id={FacebookClient.ClientId}" +
                $"&client_secret={FacebookClient.ClientSecret}" +
                $"&fb_exchange_token={_authToken}"));
 }
        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.
                }
                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();

                    // 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 = result;
                    }));
                }
            };

            //dynamic parameters = new ExpandoObject();
            //// any parameter that has "method" automatically is treated as rest api.
            //parameters.method = "pages.isFan";
            //parameters.page_id = "162171137156411";  // 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);

            fb.GetAsync(new { method = "pages.isFan", page_id = "162171137156411" });
        }
        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 } });
        }
Beispiel #20
0
        public async Task GetPhotos()
        {
            var photosResponse = await FacebookClient.GetAsync <PhotosResponse>("me/photos?fields=id&limit=50", TinderSession.CurrentSession.FbSessionInfo.FacebookToken).ConfigureAwait(false);

            foreach (var photo in photosResponse.Data)
            {
                _photos.Add(new FacebookAlbumPhotoViewModel(photo.Id));
            }
            base.RaisePropertyChanged("Photos");
        }
        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 });
        }
Beispiel #22
0
        /// <summary>
        /// Request specific user information
        /// </summary>
        /// <param name="fields">Requested fields</param>
        /// <returns>JObject with user information</returns>
        public async Task <JObject> RequestInformationAsync(string[] fields = null)
        {
            string fieldsStr = string.Empty;

            if (fields != null)
            {
                fieldsStr = string.Join(",", fields);
            }
            var response = await FacebookClient.GetAsync($"/me?fields={fieldsStr}", _authToken);

            return(response);
        }
        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"];

                IsolatedSettingsHelper.SetValue <string>("ftoken_sharetoall", accessToken);
                IsolatedSettingsHelper.SetValue <string>("fid_sharetoall", id);

                // string _post = NavigationContext.QueryString["vpost"];

                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Successfully shared on Facebook");
                });

                if (_post.Contains('|'))
                {
                    string[] words = _post.Split('|');

                    var parameters = new Dictionary <string, object>();
                    //parameters["message"] = txtMessage.Text;
                    parameters["message"] = words[0];
                    parameters["link"]    = words[1];
                    //parameters["picture"] = "";

                    fb.PostAsync("me/feed", parameters);
                }
                else
                {
                    var parameters = new Dictionary <string, object>();
                    //parameters["message"] = txtMessage.Text;
                    parameters["message"] = _post;
                    // parameters["link"] = words[1];
                    //parameters["picture"] = "";

                    fb.PostAsync("me/feed", parameters);
                }
                //////////
            };

            fb.GetAsync("me?fields=id");
        }
Beispiel #24
0
        // Load data for the ViewModel NewsItems
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                _item = App.ViewModel.ActivityItems.ElementAt(Convert.ToInt32(NavigationContext.QueryString["activityItem"]));
                if (_item == null)
                {
                    throw new Exception("Er is geen activiteit mee gegeven als argument.");
                }
                if (_item.FacebookId == null || _item.FacebookId.Equals("") || !App.ViewModel.HasConnection)
                {
                    DataContext = _item;
                    return;
                }
                _item.RsvpStatus  = GetRsvp(_item);
                _item.FriendsPics = FriendImages(_item);
                var fb = new FacebookClient
                {
                    AppId       = App.ViewModel.Appid,
                    AccessToken = App.ViewModel.UserPreference.AccessKey ??
                                  App.ViewModel.GenericId
                };

                fb.GetCompleted += (o, res) =>
                {
                    if (res.Error != null)
                    {
                        return;
                    }

                    var result    = (IDictionary <string, object>)res.GetResultData();
                    var data      = (IList <object>)result["data"];
                    var eventData = ((IDictionary <string, object>)data.ElementAt(0));

                    _item.Attendings = Convert.ToInt32(eventData["attending_count"]);
                    _item.ImageUri   = (string)eventData["pic"];

                    Dispatcher.BeginInvoke(() => DataContext = _item);
                };

                // query to get all the friends
                var query = string.Format("SELECT eid,attending_count, pic FROM event WHERE eid = {0}", _item.FacebookId);


                // 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 });
            }
            catch (Exception)
            {
                NavigationService.Navigate(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
            }
        }
        private void LoginSucceded(string accessToken)
        {
            var fb = new FacebookClient(accessToken);

            IsolatedStorageSettings.ApplicationSettings["fbAccessToken"] = 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"];
                IsolatedStorageSettings.ApplicationSettings["fbid"] = id;
                IsolatedStorageSettings.ApplicationSettings.Save();

                Dispatcher.BeginInvoke(() =>
                {
                    if (NavigationService.CanGoBack)
                    {
                        //webBrowser1.Navigate(new Uri("http://m.facebook.com/index.php?stype=lo"));

                        /*
                         * using(IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                         * {
                         *  var dir = iso.GetDirectoryNames();
                         *  var files = iso.GetFileNames("Microsoft");
                         *  var files1 = iso.GetFileNames("Shared");
                         *  var files2 = iso.GetFileNames("AppCache");
                         *  iso.DeleteDirectory("AppCache");
                         *  iso.DeleteDirectory("Microsoft");
                         *
                         * }
                         */
                        NavigationService.GoBack();
                    }
                });
            };

            fb.GetAsync("me?fields=id");
        }
Beispiel #26
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);
        }
Beispiel #27
0
        public void getFacebookUserInfo(Action <String, Exception> callback)
        {
            try
            {
                FacebookClient fb = new FacebookClient(_accessToken);
                fb.GetCompleted += (o, e) =>
                {
                    if (e.Error != null)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, e.Error.Message));
                        }
                    }

                    var result = (IDictionary <String, Object>)e.GetResultData();
                    if (result == null)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "User info coming from Facebook is empty!"));
                        }
                    }
                    else
                    {
                        if (callback != null)
                        {
                            callback(result.ToString(), null);
                        }
                    }
                };
                fb.GetAsync("me");
            }
            catch (Exception)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "Error occured while getting facebook user info."));
                }
            }
        }
        public static FbNews GetItems()
        {
            FbNews modelList = new FbNews();

            FacebookClient graph = new FacebookClient();
            var            task  = graph.GetAsync <FbNews>(accessToken, endpoint, args);

            Task.WaitAll(task);
            modelList = task.Result;

            // NewsTitel Fix
            foreach (var item in modelList.data)
            {
                if (item.story == null)
                {
                    item.story = "NetConnect hat etwas gepostet";
                }
            }

            return(modelList);
        }
Beispiel #29
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);
        }
Beispiel #30
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();
                var id     = (string)result["id"];

                //   var url = string.Format("/Pages/FacebookInfoPage.xaml?access_token={0}&id={1}", accessToken, id);
                var url = "/Pages/contacts.xaml";
                Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri(url, UriKind.Relative)));
            };

            fb.GetAsync("me?fields=id");
        }
Beispiel #31
0
        private void LegacyRestApiAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted +=
                (o, e) =>
                {
                    if (e.Error == null)
                    {
                        // there was no error, so process the result
                        bool result = e.GetResultData<bool>();

                        // to get the non genric verion call without <T>.
                        // dynamic result = e.GetResultData();

                        chkIsFanOfFacebookSdk.Checked = result;

                        if (!result)
                        {
                            lnkFacebokSdkFan.Visible = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show(e.Error.Message);
                    }
                };

            fb.GetAsync(new Dictionary<string, object>
                            {
                                { "method", "pages.isFan" },
                                { "page_id", "162171137156411" } // id of http://www.facebook.com/csharpsdk official page
                            });
        }
Beispiel #32
0
        private void GraphApiAsyncExample()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted +=
                (o, e) =>
                {
                    // note: remember to always check the error for async methods
                    if (e.Error == null)
                    {
                        // there was no error, so process the result
                        dynamic result = e.GetResultData();
                        // note: for performance remeber to cache the GetResultData() or GetResultData<T>()
                        // every time you call it will deserialize the json string into object.

                        lblFirstName.Text = "First name: " + result.first_name;
                        lblLastName.Text = "Last name: " + result.last_name;
                    }
                    else
                    {
                        MessageBox.Show(e.Error.Message);
                    }
                };

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

            //// if dynamic keyword is not supported.
            //var parameters = new Dictionary<string, object>
            //                     {
            //                         { "fields", "first_name,last_name" }
            //                     };

            fb.GetAsync("/me", parameters);
        }