/// <summary> /// Returns the <see cref="FacebookPicture"/> object associated with the logged user /// </summary> /// <returns>A <see cref="FacebookPicture"/> object</returns> public async Task <FacebookPicture> GetUserPictureInfoAsync() { if (Provider.LoggedIn) { var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookDataHost <FacebookPicture> >); PropertySet propertySet = new PropertySet { { "redirect", "0" } }; var singleValue = new FBSingleValue("/me/picture", propertySet, factory); var result = await singleValue.GetAsync(); if (result.Succeeded) { return(((FacebookDataHost <FacebookPicture>)result.Object).Data); } throw new Exception(result.ErrorInfo?.Message); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await GetUserPictureInfoAsync()); } return(null); }
private async void getFBUserInfo() { FBSession clicnt = FBSession.ActiveSession; if (clicnt.LoggedIn) { var userId = clicnt.User.Id; string endpoint = "/" + userId + "?access_token=1819087251640431|n5eZecurPAfO37og6RphwZ04tb8&fields=id,name,email,picture"; PropertySet parameters = new PropertySet(); FBSingleValue value = new FBSingleValue(endpoint, parameters, FBUserRootobject.FromJson); FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded) { try { FBUserRootobject profile = graphResult.Object as FBUserRootobject; FBPicture.UserId = userId; getFBUserDetails(profile); } catch (Exception ex) { Debug.WriteLine(ex.ToString() + "\nBrak danych"); } } } }
/// <summary> /// Retrieves a photo by id. /// </summary> /// <param name="photoId">Photo Id for the photo.</param> /// <returns>A single photo.</returns> public async Task <FacebookPhoto> GetPhotoByPhotoIdAsync(string photoId) { if (Provider.LoggedIn) { var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPhoto>); PropertySet propertySet = new PropertySet { { "fields", "images" } }; var singleValue = new FBSingleValue($"/{photoId}", propertySet, factory); var result = await singleValue.GetAsync(); if (result.Succeeded) { return((FacebookPhoto)result.Object); } throw new Exception(result.ErrorInfo?.Message); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await GetPhotoByPhotoIdAsync(photoId)); } return(null); }
private async void OnGet(object sender, RoutedEventArgs e) { FBSession clicnt = FBSession.ActiveSession; if (clicnt.LoggedIn) { var userId = clicnt.User.Id; string endpoint = "/" + userId + "/friends?fields=id,name,email,picture"; PropertySet parameters = new PropertySet(); // parameters.Add("limit", "10"); FBSingleValue value = new FBSingleValue(endpoint, parameters, Rootobject.FromJson); FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded) { try { Rootobject profile = graphResult.Object as Rootobject; string name = profile.data[0]?.name; string email = profile.data[0]?.email; MessageDialog dialog = new MessageDialog(name + "\n" + email); await dialog.ShowAsync(); } catch (Exception ex) { MessageDialog dialog = new MessageDialog(ex.ToString() + "\nBrak znajomych"); await dialog.ShowAsync(); } } } }
private async Task <string> getAppToken() { PropertySet parameters = new PropertySet(); string result = null; parameters.Add("request_host", FBSDKTokenServiceHost); parameters.Add("access_token", ""); parameters.Add("id", TestAppId); FBSingleValue sval = new FBSingleValue(FBSDKTokenApiPath, parameters, new FBJsonClassFactory((JsonText) => { JsonObject obj = null; if (!JsonObject.TryParse(JsonText, out obj)) { obj = null; } return(obj); })); FBResult fbresult = await sval.GetAsync(); if (fbresult.Succeeded) { JsonObject obj = (JsonObject)fbresult.Object; if (obj.Keys.Contains("access_token")) { result = obj.GetNamedString("access_token"); } } return(result); }
private async void GetFriends() { FBSession clicnt = FBSession.ActiveSession; if (clicnt.LoggedIn) { var userId = clicnt.User.Id; string endpoint = "/" + userId + "/friends?fields=id,name,email,picture"; PropertySet parameters = new PropertySet(); //parameters.Add("limit", "3"); FBSingleValue value = new FBSingleValue(endpoint, parameters, Rootobject.FromJson); FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded) { try { Rootobject profile = graphResult.Object as Rootobject; int friends_count = profile.data.Count(); if (Convert.ToBoolean(friends_count)) { var friendsList = new ObservableCollection <FBUserRootobject>(); for (int i = 0; i < friends_count; i++) { string id = profile.data[i]?.id; if (Database.checkIfFBUserIsSigned(id, course_id)) { friendsList.Add(new FBUserRootobject() { id = profile.data[i]?.id, name = profile.data[i]?.name, email = profile.data[i]?.email }); Debug.WriteLine("Friend {0} added to friends list.", i + 1); } } if (friendsList.Count > 0) { TitleFbFriendsTextBlock.Visibility = Visibility.Visible; FriendsList.ItemsSource = friendsList; } } } catch (Exception ex) { MessageDialog dialog = new MessageDialog(ex.ToString()); await dialog.ShowAsync(); } } } }
private static IAsyncOperation <FBResult> ExecuteAsync(string method, FBSingleValue request) { switch (method.ToLowerInvariant()) { case "delete": return(request.DeleteAsync()); case "get": return(request.GetAsync()); case "post": return(request.PostAsync()); default: throw new NotSupportedException($"Method '{method}' is not supported."); } }
private async void OnGet(object sender, RoutedEventArgs e) { string endpoint = "/me"; PropertySet parameters = new PropertySet(); parameters.Add("fields", "email"); FBSingleValue value = new FBSingleValue(endpoint, parameters, User.FromJson); FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded) { User profile = graphResult.Object as User; string email = profile?.Email; MessageDialog dialog = new MessageDialog(email); await dialog.ShowAsync(); } }
public async void GetPageWithId( string ID ) { FBSingleValue val = new FBSingleValue("/" + ID, null, new FBJsonClassFactory((JsonText) => MyFBPage.FromJson(JsonText))); FBResult result = await val.GetAsync(); if (result.Succeeded) { MyFBPage page = (MyFBPage)result.Object; //Do something with page here } else { HandleError(result.ErrorInfo); } }
private async void OnGet(object sender, RoutedEventArgs e) { string endpoint = "/me/friends"; PropertySet parameters = new PropertySet(); parameters.Add("limit", "10"); FBSingleValue value = new FBSingleValue(endpoint, parameters, Rootobject.FromJson); FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded) { Rootobject profile = graphResult.Object as Rootobject; string name = profile.data[0]?.name; MessageDialog dialog = new MessageDialog(name); await dialog.ShowAsync(); } }
/*Method keeps sending get requets to facebook api using paging, untill all pictures have been added */ private async void GetAllFbPic(PicturePlaceObject results, PropertySet parameters, string endpoint, PicturePlaceDb db) { Boolean addedAllPics = false; do //only do this while there is a next page and all pics have not been added { addedAllPics = SortPictures(results, db); //Add Results to a list if (addedAllPics == false) { parameters.Remove("after"); //Remove previous parameters parameters.Add("after", results.paging.cursors.after); //the next page to send the request too FBSingleValue value = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce FBResult graphResult = await value.GetAsync(); //check to see if the Requets Succeeded results = graphResult.Object as PicturePlaceObject; } } while ((results.paging != null || results.data.Count() != 0) && addedAllPics == false); PaintPins(db); }
/*On Successful login, send GET request to FB endpoint with params and DeserializeJson the results into objects/Dictonary */ private async void OnSuccessLogin() { string endpoint = "/me/photos";//where the url starts from PropertySet parameters = new PropertySet(); parameters.Add("fields", "source,place"); //Required fields needed FBSingleValue value = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce FBResult graphResult = await value.GetAsync(); if (graphResult.Succeeded)//check to see if the Request Succeeded { PicturePlaceObject results = graphResult.Object as PicturePlaceObject; var db = new PicturePlaceDb(); GetAllFbPic(results, parameters, endpoint, db); } else { MessageDialog dialog = new MessageDialog("Try Again Later!"); await dialog.ShowAsync(); } }
private async void LoadRoundProfilePicture( String UserId ) { PropertySet parameters = new PropertySet(); String path = "/" + UserId + "/picture"; parameters.Add(new KeyValuePair <String, Object>("redirect", "false")); // Just picking a width and height for now parameters.Add(new KeyValuePair <String, Object>("width", "200")); parameters.Add(new KeyValuePair <String, Object>("height", "200")); FBSingleValue value = new FBSingleValue(path, parameters, new FBJsonClassFactory(FBProfilePicture.FromJson)); FBResult result = await value.GetAsync(); if (result.Succeeded) { FBProfilePicture pic = (FBProfilePicture)result.Object; ProfilePicBrush.ImageSource = new BitmapImage(new Uri(pic.Url)); } }
private static IAsyncOperation<FBResult> ExecuteAsync(string method, FBSingleValue request) { switch (method.ToLowerInvariant()) { case "delete": return request.DeleteAsync(); case "get": return request.GetAsync(); case "post": return request.PostAsync(); default: throw new NotSupportedException($"Method '{method}' is not supported."); } }
private async Task<string> getAppToken() { PropertySet parameters = new PropertySet(); string result = null; parameters.Add("request_host", FBSDKTokenServiceHost); parameters.Add("access_token", ""); parameters.Add("id", TestAppId); FBSingleValue sval = new FBSingleValue(FBSDKTokenApiPath, parameters, new FBJsonClassFactory((JsonText) => { JsonObject obj = null; if (!JsonObject.TryParse(JsonText, out obj)) { obj = null; } return obj; })); FBResult fbresult = await sval.GetAsync(); if (fbresult.Succeeded) { JsonObject obj = (JsonObject)fbresult.Object; if (obj.Keys.Contains("access_token")) { result = obj.GetNamedString("access_token"); } } return result; }
private async void LoadRoundProfilePicture( String UserId ) { PropertySet parameters = new PropertySet(); String path = "/" + UserId + "/picture"; parameters.Add(new KeyValuePair<String, Object>("redirect", "false")); // Just picking a width and height for now parameters.Add(new KeyValuePair<String, Object>("width", "200")); parameters.Add(new KeyValuePair<String, Object>("height", "200")); FBSingleValue value = new FBSingleValue(path, parameters, new FBJsonClassFactory(FBProfilePicture.FromJson)); FBResult result = await value.GetAsync(); if (result.Succeeded) { FBProfilePicture pic = (FBProfilePicture)result.Object; ProfilePicBrush.ImageSource = new BitmapImage(new Uri(pic.Url)); } }