jpillora / node-edit-google-spreadsheet

A simple API for editing Google Spreadsheets
304 stars 101 forks source link

JSON Parse Error: SyntaxError: Unexpected end of input #29

Closed aprasad1993 closed 9 years ago

aprasad1993 commented 10 years ago

I am getting this error after google login and spreadsheet searching has been done. Please help me out.

app.get('/lead', function(req, res){

console.log(req.query.fullname);

Spreadsheet.load({ debug: true, spreadsheetId: '****', worksheetName: 'Sheet1', // Choose from 1 of the 3 authentication methods: // 1. Username and Password username: 'aprasad1993@gmail.com', password: '*******', // OR 2. OAuth // oauth : { // email: 'my-name@google.email.com', // keyFile: 'my-private-key.pem' // }, // // OR 3. Token // accessToken : { // type: 'Bearer', // token: 'my-generated-token' // } }, function sheetReady(err, spreadsheet) { if(err) throw err;

spreadsheet.add({ 3: { 5: "Anurag Prasad" } });

spreadsheet.send(function(err) {
  if(err) throw err;
  console.log("Updated Cell at row 3, column 5 to 'hello!'");
});

}); });

adi2412 commented 10 years ago

I think the issue is because google does not allow to fetch a list of worksheets as JSON output. Oddly though, it only allows JSON output if you fetch it using public visibility. Changing that fixes the error.

danboy commented 10 years ago

I'm getting the same error, I've tried changing the settings with no luck.

Weird thing is, it works for some spreadsheets and not others with the same sharing prefs.

@aprasad1993 did you ever figure this out?

jazzTheJackRabbit commented 10 years ago

I think this is most likely because of the update to Google sheets.

It works fine for the old sheets (with the old URL structure): https://docs.google.com/spreadsheet/ccc?key=********************************************#gid=*

And doesn't work for new Google sheets (with the URL structure): https://docs.google.com/spreadsheets/d/********************************************/edit#gid=0

So, if you make a copy from an old Spreadsheet, this node module should work with the copy (which will also be an old google spreadsheet).

This worked for me, let me know if it does work for you.

danboy commented 10 years ago

Dug a little deeper. Currently the endpoint at http://spreadsheets.google.com/feeds/worksheets/key/private/full' returns null when you pass the alt=json parameter.

If you leave it off you get an xml response.

Tooling around with xml2json right now, but it seems to produce a slightly different object than google's json parser does.

adi2412 commented 10 years ago

If you use public, it returns for json responses as well. I still haven't been able to understand why that works though

Aditya

On 21-May-2014, at 20:39, Dan Nawara notifications@github.com wrote:

Dug a little deeper. Currently the endpoint at http://spreadsheets.google.com/feeds/worksheets/key/private/full' returns null when you pass the alt=json parameter.

If you leave it off you get an xml response.

Tooling around with xml2json right now, but it seems to produce a slightly different object than google's json parser does.

— Reply to this email directly or view it on GitHub.

q2dg commented 10 years ago

Doesn't work!! I'm having this error simple running "read example" from main github page. I've tried sharing the spreadsheet as "Public" and as "Anyone who has the link" without any luck. Ooooh!!!

kmackinnon commented 10 years ago

I was able to resolve the issue by using worksheetId: 'od6' as opposed to worksheetName: 'Sheet1'

q2dg commented 10 years ago

No.

/home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:415 if(!result.feed) { ^ TypeError: Cannot read property 'feed' of undefined at /home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:415:15 at Request._callback (/home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:111:16) at Request.self.callback (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:148:22) at Request.EventEmitter.emit (events.js:110:17) at Request. (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:876:14) at Request.EventEmitter.emit (events.js:129:20) at IncomingMessage. (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:827:12) at IncomingMessage.EventEmitter.emit (events.js:129:20) at _stream_readable.js:898:16 at process._tickCallback (node.js:343:11)

I think you are talking about old format of spreadsheets (which have the "ccc=..." in the url).

sgilroy commented 10 years ago

This is a major problem for me. This bug equates to incompatibility of node-edit-google-spreadhseets with all new Google Spreadsheets, since any spreadsheet created after March 2014 will use the new version https://support.google.com/docs/answer/3544847?hl=en&ref_topic=20322

Also note that Google has warned that all existing spreadsheets will eventually be converted over to the new version.

I also made some progress using xml2json to convert the XML response, but some characters, including parenthesis are not decoded properly. I did come up with fixes for other conversion issues, including namespaces and some issues with particular uses of collections/arrays.

jpillora commented 10 years ago

Hey guys, sorry I've been a bit slack with this project - super busy at work. Is anyone interested in sending a pull request :) ?

adrienjoly commented 10 years ago

same as @kmackinnon, replacing the worksheetName parameter by worksheetId: '0' did the trick!

q2dg commented 10 years ago

No!!!!

/home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:415 if(!result.feed) { ^ TypeError: Cannot read property 'feed' of undefined at /home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:415:15 at Request._callback (/home/q2dg/node_modules/edit-google-spreadsheet/lib/index.js:111:16) at Request.self.callback (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:148:22) at Request.EventEmitter.emit (events.js:110:17) at Request. (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:876:14) at Request.EventEmitter.emit (events.js:129:20) at IncomingMessage. (/home/q2dg/node_modules/edit-google-spreadsheet/node_modules/request/index.js:827:12) at IncomingMessage.EventEmitter.emit (events.js:129:20) at _stream_readable.js:898:16 at process._tickCallback (node.js:343:11)

stockholmux commented 10 years ago

The PR from ssimono fixed my issue. Any chance of merging it into the official repo?

ChrisBAshton commented 9 years ago

For the record, the PR was merged, this issue can be closed.

jpillora commented 9 years ago

should have no more JSON issues now we're using xml2json to parse all responses