public bool Next() { var response = _fbClient.Get($"/{_appId}/accounts/test-users", _appAccessToken); var users = response["data"]; if (!users.Any()) { return(false); } foreach (var user in users) { string id = user["id"].ToString(); string loginUrl = user["login_url"].ToString(); string accessToken = user["access_token"].ToString(); Add(new FacebookTestUser(id, loginUrl, accessToken)); } var cursor = response["paging"]["cursors"]; string before = cursor["before"].ToString(); string after = cursor["after"].ToString(); Cursor = new FacebookCursor(before, after); return(true); }
/// <summary> /// Makes a request to the Facebook http API /// </summary> /// <param name="path">API endpoint</param> /// <param name="accessToken">Authentication token</param> /// <param name="cursor">Cursor of current available data (if exists)</param> /// <param name="cursorDirection">What set of results should be taken (after or before the current cursor)</param> /// <returns></returns> public async Task <JObject> GetAsync(string path, string accessToken = null, FacebookCursor cursor = null, Direction cursorDirection = Direction.None) { path = StandardizePath(path); path = AddAccessTokenToPathIfNeeded(path, accessToken); path = AddCursorToPathIfNeeded(path, cursor, cursorDirection); return(SerializeResponse(await RestClient.GetAsync($"/{GraphApiVersion}{path}", false))); }
private string AddCursorToPathIfNeeded(string path, FacebookCursor cursor, Direction cursorDirection) { var cursorPart = string.Empty; if (cursor != null && cursorDirection != Direction.None) { if (!string.IsNullOrWhiteSpace(cursor.After) && (cursorDirection == Direction.After || cursorDirection == Direction.Next)) { cursorPart = (path.Contains("?") ? "&" : "?") + "after=" + cursor.After; } else if (!string.IsNullOrWhiteSpace(cursor.Before)) { cursorPart = (path.Contains("?") ? "&" : "?") + "before=" + cursor.Before; } } return(path + cursorPart); }
/// <summary> /// Makes a request to the Facebook http API /// </summary> /// <param name="path">API endpoint</param> /// <param name="accessToken">Authentication token</param> /// <param name="cursor">Cursor of current available data (if exists)</param> /// <param name="cursorDirection">What set of results should be taken (after or before the current cursor)</param> /// <returns></returns> public async Task <JObject> GetAsync(string path, string accessToken = null, FacebookCursor cursor = null, Direction cursorDirection = Direction.None) { if (!path.StartsWith("/")) { path = "/" + path; } if (accessToken == null) { accessToken = string.Empty; } else { accessToken = (path.Contains("?") ? "&" : "?") + "access_token=" + accessToken; } string cursorStr = string.Empty; if (cursor != null && cursorDirection != Direction.None) { if ((cursorDirection == Direction.After || cursorDirection == Direction.Next) && !string.IsNullOrWhiteSpace(cursor.After)) { cursorStr = (path.Contains("?") ? "&" : "?") + "after=" + cursor.After; } else if (!string.IsNullOrWhiteSpace(cursor.Before)) { cursorStr = (path.Contains("?") ? "&" : "?") + "before=" + cursor.Before; } } var response = await RestClient.GetAsync($"/{GraphApiVersion}{path}{accessToken}{cursorStr}", false); var serializedResponse = SerializeResponse(response); return(serializedResponse); }