public async Task <IReadOnlyList <Object> > getListOfTestUsers() { string token = await getAppToken(); PropertySet parameters = new PropertySet(); string path = "/" + TestAppId + FBSDKTestUsersPath; //Assert.IsNotNull(token); parameters.Add("access_token", Uri.EscapeUriString(token)); FBPaginatedArray arr = new FBPaginatedArray(path, parameters, new FBJsonClassFactory(FBTestUser.FromJson)); FBResult result = await arr.First(); //Assert.IsTrue(result.Succeeded); IReadOnlyList <Object> users = null; try { users = (IReadOnlyList <Object>)result.Object; } catch (InvalidCastException) { Assert.IsTrue(false, "Item returned is not expected type" + " (IReadOnlyList<Object>)"); } return(users); }
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; } } }
public void parseArrayOfLikes() { string FBArrayOfLikes = "{\"data\":[" + SampleJsonPage + "," + SampleJsonPage2 + "," + SampleJsonPage3 + "," + SampleJsonPage4 + "],\"paging\":" + PagingObjectJson + "}"; string fbResponse = FBArrayOfLikes; FBPaginatedArray arr = new FBPaginatedArray("Unused", null, new FBJsonClassFactory( (JsonText) => FBPage.FromJson(JsonText))); IReadOnlyList <object> result = arr.ObjectArrayFromWebResponse( fbResponse, new FBJsonClassFactory( (JsonText) => FBPage.FromJson(JsonText))); for (int i = 0; i < result.Count; i++) { object obj = result[i]; FBPage page = (FBPage)result[i]; Assert.IsNotNull(obj); Assert.IsNotNull(page); StringAssert.Equals(page.Name, PageNames[i]); } }
public async Task testListTestUsers() { string token = await getAppToken(); PropertySet parameters = new PropertySet(); string path = "/" + TestAppId + FBSDKTestUsersPath; Assert.IsNotNull(token); bool found = false; parameters.Add("access_token", Uri.EscapeUriString(token)); //Ensure we have at least one test user! FBTestUser user = await createTestUser(parameters); FBPaginatedArray arr = new FBPaginatedArray(path, parameters, new FBJsonClassFactory(FBTestUser.FromJson)); FBResult result = await arr.First(); Assert.IsTrue(result.Succeeded); IReadOnlyList <Object> users = (IReadOnlyList <Object>)result.Object; Assert.IsTrue(users.Count > 0); for (int i = 0; i < users.Count; i++) { try { FBTestUser testuser = (FBTestUser)users[i]; if (string.CompareOrdinal(testuser.Id, user.Id) == 0) { found = true; } } catch (InvalidCastException) { Assert.IsTrue(false, "Item returned is not expected type" + " (FBTestUser)"); } } Assert.IsTrue(found); await deleteTestUser(user); }
/// <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 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); } } }
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); }
internal static async Task PopulateUserPages() { Pages.Clear(); String graphPath = "me/accounts"; FBPaginatedArray fbPages = new FBPaginatedArray(graphPath, null, FBPage.Factory); FBResult result = null; do { if (result == null) { result = await fbPages.FirstAsync(); } else { result = await fbPages.NextAsync(); } if (result.Succeeded) { IReadOnlyList <object> pages = (IReadOnlyList <object>)result.Object; foreach (var p in pages) { FBPage page = (FBPage)p; if (page != null) { Pages.Add(page); } } } else { FBErrorHandler.HandleError(result); } } while (fbPages.HasNext); }
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); } } }
public async Task testListTestUsers() { string token = await getAppToken(); PropertySet parameters = new PropertySet(); string path = "/" + TestAppId + FBSDKTestUsersPath; Assert.IsNotNull(token); bool found = false; parameters.Add("access_token", Uri.EscapeUriString(token)); //Ensure we have at least one test user! FBTestUser user = await createTestUser(parameters); FBPaginatedArray arr = new FBPaginatedArray(path, parameters, new FBJsonClassFactory(FBTestUser.FromJson)); FBResult result = await arr.FirstAsync(); Assert.IsTrue(result.Succeeded); IReadOnlyList<Object> users = (IReadOnlyList<Object>)result.Object; Assert.IsTrue(users.Count > 0); for (int i = 0; i < users.Count; i++) { try { FBTestUser testuser = (FBTestUser)users[i]; if (string.CompareOrdinal(testuser.Id, user.Id) == 0) { found = true; } } catch (InvalidCastException) { Assert.IsTrue(false, "Item returned is not expected type" + " (FBTestUser)"); } } Assert.IsTrue(found); await deleteTestUser(user); }
public async Task<IReadOnlyList<Object>> getListOfTestUsers() { string token = await getAppToken(); PropertySet parameters = new PropertySet(); string path = "/" + TestAppId + FBSDKTestUsersPath; //Assert.IsNotNull(token); parameters.Add("access_token", Uri.EscapeUriString(token)); FBPaginatedArray arr = new FBPaginatedArray(path, parameters, new FBJsonClassFactory(FBTestUser.FromJson)); FBResult result = await arr.FirstAsync(); //Assert.IsTrue(result.Succeeded); IReadOnlyList<Object> users = null; try { users = (IReadOnlyList<Object>)result.Object; } catch (InvalidCastException) { Assert.IsTrue(false, "Item returned is not expected type" + " (IReadOnlyList<Object>)"); } return users; }
public void parseArrayOfLikes() { string FBArrayOfLikes = "{\"data\":[" + SampleJsonPage + "," + SampleJsonPage2 + "," + SampleJsonPage3 + "," + SampleJsonPage4 + "],\"paging\":" + PagingObjectJson + "}"; string fbResponse = FBArrayOfLikes; FBPaginatedArray arr = new FBPaginatedArray("Unused", null, new FBJsonClassFactory( (JsonText) => FBPage.FromJson(JsonText))); IReadOnlyList<object> result = arr.ObjectArrayFromWebResponse( fbResponse, new FBJsonClassFactory( (JsonText) => FBPage.FromJson(JsonText))); for (int i = 0; i < result.Count; i++) { object obj = result[i]; FBPage page = (FBPage)result[i]; Assert.IsNotNull(obj); Assert.IsNotNull(page); StringAssert.Equals(page.Name, PageNames[i]); } }