/// <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); }
public async void GetUserLikes() { if (FBSession.ActiveSession.LoggedIn) { string graphPath = FBSession.ActiveSession.User.Id + "/likes"; FBJsonClassFactory fact = new FBJsonClassFactory( (JsonText) => MyFBPage.FromJson(JsonText)); _likes = new FBPaginatedArray(graphPath, null, fact); FBResult result = await _likes.FirstAsync(); if (result.Succeeded) { BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed; LikesListView.Visibility = Windows.UI.Xaml.Visibility.Visible; if (_likes.Current.Count > 0) { AddLikes(_likes.Current); } else { LikesListView.Visibility = Windows.UI.Xaml.Visibility.Collapsed; BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; BadResultsTextBlock.Text = "No User likes found"; } } else { LikesListView.Visibility = Windows.UI.Xaml.Visibility.Collapsed; BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; BadResultsTextBlock.Text = result.ErrorInfo.Message; } } }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="FacebookRequestSource{T}"/> class. /// </summary> /// <param name="config">Config containing query information.</param> /// <param name="fields">Comma-separated list of properties expected in the JSON response. Accompanying properties must be found on the strong-typed T.</param> /// <param name="limit">A string representation of the number of records for page - i.e. pageSize.</param> /// <param name="maxPages">Upper limit of pages to return.</param> public FacebookRequestSource(FacebookDataConfig config, string fields, string limit, int maxPages) { _config = config; _fields = fields; _limit = limit; _maxPages = maxPages; _propertySet = new PropertySet { { "fields", _fields }, { "limit", _limit } }; _factory = new FBJsonClassFactory(s => JsonConvert.DeserializeObject(s, typeof(T))); // FBPaginatedArray does not allow us to set page size per request so we must go with first supplied - see https://github.com/Microsoft/winsdkfb/issues/221 _paginatedArray = new FBPaginatedArray(_config.Query, _propertySet, _factory); }
public async Task <string> PostPictureToFeedAsync(string title, string pictureName, IRandomAccessStreamWithContentType pictureStream) { if (pictureStream == null) { return(null); } if (Provider.LoggedIn) { var facebookPictureStream = new FBMediaStream(pictureName, pictureStream); var parameters = new PropertySet { { "source", facebookPictureStream }, { "name", title } }; string path = FBSession.ActiveSession.User.Id + "/photos"; var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPicture>); var singleValue = new FBSingleValue(path, parameters, factory); var result = await singleValue.PostAsync(); if (result.Succeeded) { var photoResponse = result.Object as FacebookPicture; if (photoResponse != null) { return(photoResponse.Id); } } return(null); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await PostPictureToFeedAsync(title, pictureName, pictureStream)); } return(null); }
public async void GetUserLikes() { if (FBSession.ActiveSession.LoggedIn) { string graphPath = FBSession.ActiveSession.User.Id + "/likes"; FBJsonClassFactory fact = new FBJsonClassFactory( (JsonText) => MyFBPage.FromJson(JsonText)); _likes = new FBPaginatedArray(graphPath, null, fact); FBResult result = await _likes.FirstAsync(); if (result.Succeeded) { IReadOnlyList <object> pages = (IReadOnlyList <object>)result.Object; AddLikes(pages); } } }
/// <summary> /// Enables direct posting data to the timeline. /// </summary> /// <param name="title">Title of the post.</param> /// <param name="message">Message of the post.</param> /// <param name="description">Description of the post.</param> /// <param name="link">Link contained as part of the post. Cannot be null</param> /// <param name="pictureUrl">URL of a picture attached to this post. Can be null</param> /// <returns>Task to support await of async call.</returns> public async Task <bool> PostToFeedAsync(string title, string message, string description, string link, string pictureUrl = null) { if (Provider.LoggedIn) { var parameters = new PropertySet { { "title", title }, { "message", link }, { "description", description }, { "link", link } }; if (!string.IsNullOrEmpty(pictureUrl)) { parameters.Add(new KeyValuePair <string, object>("picture", pictureUrl)); } string path = FBSession.ActiveSession.User.Id + "/feed"; var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPost>); var singleValue = new FBSingleValue(path, parameters, factory); var result = await singleValue.PostAsync(); if (result.Succeeded) { var postResponse = result.Object as FacebookPost; if (postResponse != null) { return(true); } } Debug.WriteLine(string.Format("Could not post. {0}", result.ErrorInfo?.ErrorUserMessage)); return(false); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await PostToFeedAsync(title, message, description, link, pictureUrl)); } return(false); }
public async Task testFBPaginatedArray() { MockHttpClient mockHttpClient = new MockHttpClient(); HttpManager.Instance.SetHttpClient(mockHttpClient); // test no values returned from request mockHttpClient.ResponseData = @"{""data"":[]}"; String graphPath = @"/12345/likes"; Func <string, string> dumbFunc = (string a) => { return(a); }; FBJsonClassFactory fact = new FBJsonClassFactory( (JsonText) => dumbFunc(JsonText)); FBPaginatedArray likes = new FBPaginatedArray(graphPath, null, fact); FBResult result = await likes.FirstAsync(); Assert.IsTrue(likes.HasCurrent); Assert.IsFalse(likes.HasNext); Assert.IsFalse(likes.HasPrevious); // test with next but no previous }
/// <summary> /// Request generic list data from service provider based upon a given config / query. /// </summary> /// <typeparam name="T">Strong type of model.</typeparam> /// <param name="config">FacebookDataConfig instance.</param> /// <param name="maxRecords">Upper limit of records to return.</param> /// <param name="fields">A comma seperated string of required fields, which will have strongly typed representation in the model passed in.</param> /// <returns>Strongly typed list of data returned from the service.</returns> public async Task <List <T> > RequestAsync <T>(FacebookDataConfig config, int maxRecords = 20, string fields = "id,message,from,created_time,link,full_picture") { if (Provider.LoggedIn) { var processedResults = new List <T>(); PropertySet propertySet = new PropertySet { { "fields", fields } }; var factory = new FBJsonClassFactory(s => JsonConvert.DeserializeObject(s, typeof(T))); paginatedArray = new FBPaginatedArray(config.Query, propertySet, factory); var result = await paginatedArray.FirstAsync(); if (result.Succeeded) { IReadOnlyList <object> results = (IReadOnlyList <object>)result.Object; await ProcessResultsAsync(results, maxRecords, processedResults); return(processedResults); } throw new Exception(result.ErrorInfo?.Message); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await RequestAsync <T>(config, maxRecords, fields)); } return(null); }
public void tryCreatePageViaClassFactory() { string[] pages = { SampleJsonPage, SampleJsonPage2, SampleJsonPage3, SampleJsonPage4 }; for (int i = SAMPLE_PAGE_INDEX; i <= SAMPLE_PAGE4_INDEX; i++) { FBJsonClassFactory fact = new FBJsonClassFactory( (JsonText) => FBPage.FromJson(JsonText)); object obj = fact(pages[i]); FBPage page = (FBPage)obj; Assert.IsNotNull(obj); Assert.IsNotNull(page); StringAssert.Equals(page.Name, PageNames[i]); StringAssert.Equals(page.Category, PageCategories[i]); StringAssert.Equals(page.Id, PageIds[i]); } }
public async Task <bool> PostToFeedAsync(string link) { if (Provider.LoggedIn) { var parameters = new PropertySet { { "link", link } }; string path = FBSession.ActiveSession.User.Id + "/feed"; var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPost>); var singleValue = new FBSingleValue(path, parameters, factory); var result = await singleValue.PostAsync(); if (result.Succeeded) { var postResponse = result.Object as FacebookPost; if (postResponse != null) { return(true); } } Debug.WriteLine(string.Format("Could not post. {0}", result.ErrorInfo?.ErrorUserMessage)); return(false); } var isLoggedIn = await LoginAsync(); if (isLoggedIn) { return(await PostToFeedAsync(link)); } return(false); }
public async void GetUserLikes() { if (FBSession.ActiveSession.LoggedIn) { string graphPath = FBSession.ActiveSession.User.Id + "/likes"; FBJsonClassFactory fact = new FBJsonClassFactory( (JsonText) => MyFBPage.FromJson(JsonText)); _likes = new FBPaginatedArray(graphPath, null, fact); FBResult result = await _likes.First(); if (result.Succeeded) { IReadOnlyList<object> pages = (IReadOnlyList<object>)result.Object; AddLikes(pages); } } }
private static async void FacebookPoster() { // Get active session FBSession sess = FBSession.ActiveSession; if (sess.LoggedIn) { var user = sess.User; // Set caption, link and description parameters var parameters = new PropertySet(); // Add post message await LocationAccesser(); parameters.Add("message", _message + "\n" + "\n" + _latitude + "\n" + _longitude); // Set Graph api path var path = "/" + user.Id + "/feed"; var factory = new FBJsonClassFactory(s => { return JsonConvert.DeserializeObject<FBReturnObject>(s); }); var singleValue = new FBSingleValue(path, parameters, factory); var result = await singleValue.PostAsync(); if (result.Succeeded) { Debug.WriteLine("Succeed"); } else { Debug.WriteLine("Failed"); } } }
private async Task FacebookPoster() { // Get active session FBSession sess = FBSession.ActiveSession; SosPageText += "\n Getting active Facebook Session..."; RaisePropertyChanged(() => SosPageText); if (sess.LoggedIn) { var user = sess.User; // Set caption, link and description parameters var parameters = new PropertySet(); // Add post message await LocationAccesser(); parameters.Add("message", Message + "\n" + "\n" + _latitude + "\n" + _longitude); // Set Graph api path var path = "/" + user.Id + "/feed"; var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject<FBReturnObject>); var singleValue = new FBSingleValue(path, parameters, factory); var result = await singleValue.PostAsync(); if (result.Succeeded) { SosPageText += "\n Posted to Facebook Wall \n"; } else { SosPageText += "\n Can't post to Facebook Wall \n"; } } else { SosPageText += "\n Facebook Not Configured or Active session not available! "; RaisePropertyChanged(() => SosPageText); } RaisePropertyChanged(()=>SosPageText); }