Cannot find any documentation for this...
Currently using the following code to get a list of my photos:
FacebookApp fb = new FacebookApp(accessToken);
dynamic test = fb.Get("me/photos");
I'm cycling through the first 25 photos that it returns. Simple.
Now how do it get it to return the next 25?
So far I've tried this:
FacebookApp fb = new FacebookApp(accessToken);
string query = "me/photos";
while (true)
{
dynamic test = fb.Get(query);
foreach (dynamic each in test.data)
{
// do something here
}
query = test.paging.next;
}
but it fails throwing:
Could not parse '2010-08-30T17%3A58%3A56%2B0000' into a date or time.
Do I have to use a fresh dynamic variable for every request, or am I going about this the wrong way completely?
Ended up finding this:
// first set (1-25)
var parameters = new ExpandoObject();
parameters.limit = 25;
parameters.offset = 0;
app.Api("me/friends", parameters);
// next set (26-50)
var parameters = new ExpandoObject();
parameters.limit = 25;
parameters.offset = 25;
app.Api("me/friends", parameters);
I also found you can use this.
// for the first 25 albums (in this case) 1-25
dynamic albums = client.Get("me/albums", new { limit = "25", offset = "0"});
// for the next 25 albums, 26-50
dynamic albums = client.Get("me/albums", new { limit = "25", offset = "25"});
Worked the same as you used above.
Related
When executing code that uses the Google Sheets API to sort a sheet A to Z, I get an error that I don't know how to fix.
Message[Invalid requests[0].sortRange: No sort order specified.] Location[ - ] Reason[badRequest] Domain[global]
Using this code, it should have created sort order and dimension index, and put it into SortSpec, which was added to SortRange, but it doesn't seem like Google Sheets recognizes that.
List<Data.Request> requests = new List<Data.Request>(); // TODO: Update placeholder value.
Data.SortSpec so = new Data.SortSpec();
so.SortOrder = "ASCENDING";
Data.SortSpec di = new Data.SortSpec();
di.DimensionIndex = 0;
List<Data.SortSpec> ss = new List<Data.SortSpec>();
ss.Add(so);
ss.Add(di);
var test = new Request()
{
SortRange = new SortRangeRequest()
{
Range = new GridRange()
{
SheetId = 0,
StartRowIndex = 1
},
SortSpecs = ss
}
};
requests.Add(test);
// TODO: Assign values to desired properties of `requestBody`:
Data.BatchUpdateSpreadsheetRequest requestBody = new Data.BatchUpdateSpreadsheetRequest();
requestBody.Requests = requests;
SpreadsheetsResource.BatchUpdateRequest request = service.Spreadsheets.BatchUpdate(requestBody, spreadsheetId);
Data.BatchUpdateSpreadsheetResponse response = request.Execute();
Using debug within Visual Studio, I looked through Autos to see what values request had for SortSpecs, and I found that both values were there.
- [0] {Google.Apis.Sheets.v4.Data.SortSpec} Google.Apis.Sheets.v4.Data.SortSpec
DimensionIndex null int?
ETag null string
SortOrder "ASCENDING" string
- [1] {Google.Apis.Sheets.v4.Data.SortSpec} Google.Apis.Sheets.v4.Data.SortSpec
DimensionIndex 0 int?
ETag null string
SortOrder null string
Answer was very simple. Instead of creating seperate sortspecs within the list, you must define dimension index and sort order to the same variable
Data.SortSpec so = new Data.SortSpec();
so.SortOrder = "ASCENDING";
so.DimensionIndex = 0;
List<Data.SortSpec> ss = new List<Data.SortSpec>();
ss.Add(so);
Forgive me if this is redundant or I'm missing something simple, but I'm playing around with ElasticSearch (and NEST in particular) to see if it would be a good add for our b2b ecommerce site's search function.
I grabbed the latest NuGet of NEST and then tried to serialize and add something to an index. Here is a snippet of the approach I was using
var localhost = new Uri("http://localhost/9200");
var setting = new ConnectionSettings(localhost).SetDefaultIndex("cpi_catalog");
var client = new ElasticClient(setting);
client.MapFromAttributes<Item>();
var testitem = new Item()
{
Description = "test",
Id = 9999999,
Manufacturer_Id = 5,
Quantity_Per_Unit = 1,
Quantity_Unit_Id = "EA",
SKU = "AVE29845",
Subtitle = "test",
Title = "test"
};
var status = client.Index(testitem);
However, it seems that testitem is never indexed at all, when I do a GET for /cpi_catalog/items/9999999 I get the following:
{"_index":"cpi_catalog","_type":"items","_id":"9999999","exists":false}
What seemingly simple thing am I missing here?
EDIT: When debugging, I get back a Nest.IndexResponse with all fields NULL besides status.OK which is false
Seems like the uri is has a typo:
var localhost = new Uri("http://localhost/9200");
should probably be:
var localhost = new Uri("http://localhost:9200");
I'm trying to use the .net client library for Google Calendar. I can get a list of Calendars and get a list of events on a Calendar. However, I get a maximum of 250 items per Calendar. How do I access the rest? I'm aware of the 'pagetoken' in Google.Apis.Calendar.v3.EventsResource.ListRequest, however in the code example below, itemlistreq.PageToken remains null, even for a calendar with more than 250 items.
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
var initializer = new BaseClientService.Initializer();
initializer.Authenticator = auth;
var calsrv = new CalendarService(initializer);
//Get list of calendars
var list = calsrv.CalendarList.List().Execute().Items;
//Get entry list for each calendar
foreach(var cal in list)
{
var itemlistreq = calsrv.Events.List(cal.Id);
var itemlistex = itemlistreq.Execute();
var itemlist = itemlistex.Items;
//Here, itemlistreq.PageToken == null, even if itemlist has 250 entries.
}
Did you try to change the MaxResult property on the request?
For example, try doing the following:
var itemlistreq = calsrv.Events.List(cal.Id);
itemlistreq.MaxResults = 10000;
var itemlistex = itemlistreq.Execute();
var itemlist = itemlistex.Items;
UPDATED:
Try getting the NextPageToekn property from the Events class (itemlistex in your case)
var itemlistreq = calsrv.Events.List(cal.Id);
var itemlistex = itemlistreq.Execute();
var token = itemlistex.NextPageToken; // THAT IS THE TOKEN YOU ARE LOOKING FOR
var itemlist = itemlistex.Items;
Then you can set it on the itemlistex.PageToken property to get more events...
the MaxResult is limited to 2500 items, so 10000 will not work
I'm using Rob Conery's Massive to connect to my database, but I don't seem to be able to be able to save a list of dynamic objects to the database. I thought this was supported though.
Here's the code I am attempting to use:
int numberOfChildren = int.Parse(Request.Form["numberOfChildren"]);
List<dynamic> children = new List<dynamic>();
for(int i = 1; i <= numberOfChildren; i++) {
dynamic child = new ExpandoObject();
child.FamilyID = familyId;
child.Type = "CHILD";
child.LastName = Request.Form[i + "-childLastName"];
child.FirstName = Request.Form[i + "-childFirstName"];
child.SendSmsAlerts = false;
child.Gender = Request.Form[i + "-childGender"];
child.Birthdate = Request.Form[i + "-childBirthdate"];
children.Add(child);
}
var people = new People();
people.Save(children);
I get a "Parameter count mismatch." error on line 78 of Massive.cs
Everything works fine if i only pass in a single dynamic object at a time, the error is only raised when I attempt to pass in the list. Based on the documentation on GitHub I thought this was supported and it would save all the children in one transaction.
Save takes an params array not a list.
people.Save(children.ToArray());
This code works correctly to make a web service call:
int numberOfGuests = Convert.ToInt32(search.Guest);
var list = new List<Guest>();
Guest adult = new Guest();
adult.Id = 1;
adult.Title = "Mr";
adult.Firstname = "Test";
adult.Surname = "Test";
list.Add(adult);
Guest adult2 = new Guest();
adult2.Id = 2;
adult2.Title = "Mr";
adult2.Firstname = "Test";
adult2.Surname = "Test";
list.Add(adult2);
Guest[] adults = list.ToArray();
How do I build the list dynamically using the numberofguests variable to create the list? The output has to match the output shown exactly else the web service call fails, so adult.id = 1, adult2.id = 2, adult3.id = 3, etc...
Do you know about loops?
for (int i = 1; i <= numberofGuests; i++) {
var adult = new Guest();
adult.Id = i;
adult.Title = "Mr";
adult.Firstname = "Test";
adult.Surname = "Test";
list.Add(adult)
}
This runs the code within the loop once from 1 to numberOfGuests, setting the variable i to the current value.
The Linq way :-)
var list = (from i in Enumerable.Range(1, numberOfGuests)
select new Guest
{
Id = i,
Title = "Mr.",
Firstname = "Test",
Surname = "Test"
}).ToList();
You need a for loop. Or, better yet, a decent C# book -- these are really basics of C#.
Are you asking how to display a list dynamically? I'm not really sure what the question here is about, as the other answers say if you know the value of numberofGuests then you can just use a loop to go through your list.
I suspect you are wondering how to obtain this information in the first place, am I right? If you want to dynamically add controls to a page (your previous post suggest this was ASP.Net I think?), so that you only display the correct number of controls then take a look at these related questions:
Dynamically adding controls in ASP.NET Repeater
ASP.NET - How to dynamically generate Labels