MightKamioka / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

service.Insert(listFeed, row) gives error while inserting a row in worksheet of a spreadsheet #637

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
See the code below. 
1. I have connected service
2. searched in worksheets
3. finally while creating the worksheet the worksheet gets created with no of 
rows and columns
4. Now I am trying to connect to the newly inserted worksheet for inserting new 
rows with some data. At my first entry it got failed with follwing error:
"Execution of request failed: 
https://spreadsheets.google.com/feeds/list/tVk0Ia6n8RF9pONzDpUGnPQ/oci/private/f
ull"

What is the expected output? What do you see instead?
Row must get inserted

What version of the product are you using? On what operating system?
I am using .NET with C#, Google API for spreadsheet I am using in it.
Version of google API is 2.1
OS: Windows 7
.NET version: 4.0

Please provide any additional information below.
See the code below and let me know if there is any issue from my side.
This is not full code but the code required for your analysis.

// Create a local representation of the new worksheet.
WorksheetEntry worksheet = new WorksheetEntry();
worksheet.Title.Text = "Company " + DateTime.Now;
worksheet.Cols = 2;
//Names is a List<string>
worksheet.Rows = (uint)(Names.Count + 1);

// Send the local representation of the worksheet to the API for
// creation.  The URL to use here is the worksheet feed URL of our
// spreadsheet.
WorksheetFeed wsFeed = spreadSheet.Worksheets;
service.Insert(wsFeed, worksheet);
WorksheetFeed wsFeed = spreadSheet.Worksheets;
service.Insert(wsFeed, worksheet);

wsFeed = spreadSheet.Worksheets;
foreach (WorksheetEntry entry in wsFeed.Entries)
{
    if (entry.Title.Text == worksheetText)
    {
        worksheet = entry;
        break;
    }
}

// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = 
worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "Name", Value = "Name" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "URL", Value = "URL" });

// Send the new row to the API for insertion.
service.Insert(listFeed, row);

Original issue reported on code.google.com by dhananja...@clariontechnologies.co.in on 24 Nov 2012 at 11:44

GoogleCodeExporter commented 8 years ago
Please use Fiddler to capture the HTTP traffic and inspect the response, it 
will contain a more descriptive error message telling why the request failed.
You can also get the same error message by drilling down into the exception.

Original comment by ccherub...@google.com on 24 Nov 2012 at 6:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Can't you help me about the problem by seeing my code provided in the section 
"Please provide any additional information below."? I am getting error at last 
line i.e. "service.Insert(listFeed, row);". If there is any wrong in code just 
let me know, till time I check with fiddler. Your help is highly appreciable.
Thanks for your help!!

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 4:11

GoogleCodeExporter commented 8 years ago
When using the List feed, the first row of the worksheet is used as the header 
row. That means your code has to address the columns with the names that are 
listed in the first row. 

You are using "Name" and "URL" as the column names in your code. Does the 
spreadsheet have those values in the first row? If not, your insert request 
will fail.

I'm closing this as working as intended, if that is not the case I need the 
HTTP capture to understand what is not working in your code and reopen the 
issue.

Original comment by ccherub...@google.com on 26 Nov 2012 at 4:16

GoogleCodeExporter commented 8 years ago
As you have suggested I have checked the response in the fiddler but I didn't 
get any. I get innerexception while debugging in the visual studio. Inner 
exception says, "The remote server returned an error: (400) Bad Request.".

Comment on your comment 5:
I don't have anything in newly inserted worksheet. I am trying to insert a 
firstrow with the following code and I am getting the above exception.
// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = 
worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "Name", Value = "Name" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "URL", Value = "URL" });

// Send the new row to the API for insertion.
service.Insert(listFeed, row);

Now tell me how shall I insert my first row in the worksheet? I am following 
the code from the link 
"https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row"

Please help me.

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 5:37

GoogleCodeExporter commented 8 years ago
See the following links. There also people didn't get solution to insert a row 
in worksheet of google:

http://stackoverflow.com/questions/10518694/adding-a-row-to-a-google-spreadsheet

http://stackoverflow.com/questions/13008293/exception-during-adding-a-row-to-goo
gle-spreadsheet

How can you say that everything is fine?
One more thing I am not able to reopen the issue. You check it.

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 5:53

GoogleCodeExporter commented 8 years ago
In the second Stack Overflow question you linked I explained how the list-based 
feed of the Spreadsheets API works. Basically, this feed can only be used when 
the spreadsheet has a know structure (i.e. header row).

Original comment by ccherub...@google.com on 26 Nov 2012 at 5:07

GoogleCodeExporter commented 8 years ago
I was having a similar issue and found that the LocalName must be all in lower 
case.  So, in your case try the following:

row.Elements.Add(new ListEntry.Custom() { LocalName = "name", Value = "Name" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "url", Value = "URL" });

Apparently spaces should also be removed from the column names.
http://eveinfo.net/wiki/refer~17.htm#gsx_reference

I wish I could find this in Google's own documentation.  It's probably there 
somewhere, but way too hard to track down.

Hope this helps,
Matt

Original comment by matheson...@gmail.com on 2 Apr 2013 at 5:39