无法使用基于单元格的端点从nodejs更新Google电子表格中的值 [英] Unable to update values in google spreadsheets from nodejs using the cell based endpoints

查看:83
本文介绍了无法使用基于单元格的端点从nodejs更新Google电子表格中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个谷歌电子表格,它已发布并可供任何人编辑。我可以检索基于单元格的结果,但是当我尝试更新单元格我无法这样做。我也尝试使用经过验证的结果,但仍然没有运气。不知道如何在这里继续,任何想法我做错了。

I have a google spreadsheet which is both published and available for anyone to edit. I'm able to retrieve the cell-based results, but when I try to update the cell I am unable to do so. I have also tried using the authenticated result but still no luck. Not sure how to proceed here, Any ideas what I am doing wrong.

var https = require('https');
var opt = {
        host: "spreadsheets.google.com",
        path: "/feeds/cells/key/od6/public/full/R2C4",
        method:"PUT"
    };

var request = https.request(opt, function(res){
        res.setEncoding('utf8');
        console.log('the header os '+ JSON.stringify(res.headers));
        var XMLoutput='';
        res.on('data',function(chunk){
            XMLoutput+=chunk;
        });
        res.on('end',function(){
        console.log('the data is  '+ XMLoutput);
        });
    });
    request.on('error',function(e){
        console.log('the error is '+ e);
    });
    request.write('<entry xmlns="http://www.w3.org/2005/Atom"    xmlns:gs="http://schemas.google.com/spreadsheets/2006">'+
                    '<id>https://spreadsheets.google.com/feeds/cells/key/od6/public/full/R2C4</id>'+
                    '<link rel="edit" type="application/atom+xml" href="https://spreadsheets.google.com/feeds/cells/key/od6/public/full/R2C4"/>'+
                    '<gs:cell row="2" col="4" inputValue="someValue"/>'+
                 '</entry>');
    request.end();


推荐答案

我终于搞定了;我必须正确使用授权密钥。希望下面的代码有帮助!

I finally got it working; I had to use the Authorization key correctly. Hope the below code helps!

var https = require('https');
var opt = {
        host: "spreadsheets.google.com",
        path: "/feeds/cells/key/od6/private/basic/R2C4",
        method:"PUT",
        headers : {"content-type":"application/atom+xml","Authorization":"GoogleLogin Auth=actualAuthkey","GData-Version": "3.0","If-Match": "*"}
    };

var request = https.request(opt, function(res){
        res.setEncoding('utf8');
        console.log('the header os '+ JSON.stringify(res.headers));
        var XMLoutput='';
        res.on('data',function(chunk){
            XMLoutput+=chunk;
        });
        res.on('end',function(){
        console.log('the data is  '+ XMLoutput);
        });
    });
    request.on('error',function(e){
        console.log('the errir is '+ e);
    });
    request.write('<entry xmlns="http://www.w3.org/2005/Atom"    xmlns:gs="http://schemas.google.com/spreadsheets/2006">'+
                    '<id>https://spreadsheets.google.com/feeds/cells/key/private/basic/R2C4</id>'+
                    '<link rel="edit" type="application/atom+xml" href="https://spreadsheets.google.com/feeds/cells/key/od6/private/basic/R2C4"/>'+
                    '<gs:cell row="2" col="4" inputValue="xyz"/>'+
                 '</entry>');
    request.end();

这篇关于无法使用基于单元格的端点从nodejs更新Google电子表格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆