有没有办法在没有使用java的OAuth的情况下在Google Spreadsheet上添加一行? [英] Is there a way to add a row on a Google Spreadsheet without OAuth using java?

查看:103
本文介绍了有没有办法在没有使用java的OAuth的情况下在Google Spreadsheet上添加一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多关于如何使用电子表格键的网站,但没有成功。我可以检索它,获取我想要的所有数据,但是我无法追加新行。



我已经将我的电子表格发布到网络上,使它公开,但我不断收到com.google.gdata.util.ServiceException:方法不允许。



这就是我试图做到这一点:

  SpreadsheetService服务= 
新SpreadsheetService(MySpreadsheetIntegration-v1);

尝试{

URL url = FeedURLFactory.getDefault()。getWorksheetFeedUrl(SpreadsheetRequest.KEY,public,full); // KEY =1cenwTRlrGMzMTufkK27IIgAHvEGwVKR9Yr59Qako3u0;

WorksheetFeed worksheetFeed = service.getFeed(url,WorksheetFeed.class);
列表< WorksheetEntry>工作表= worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);

URL listFeedUrl = worksheet.getListFeedUrl();

ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);
List< ListEntry> list = listFeed.getEntries();

//检查所有条目,像(b)ListEntry row:list {
Log.i(INSERT,row.getTitle()。getPlainText ()+\t
+ row.getPlainTextContent());
}

ListEntry row = new ListEntry();

row.getCustomElements()。setValueLocal(id,21);
row.getCustomElements()。setValueLocal(type,si.getType()。toString());
row.getCustomElements()。setValueLocal(longitude,String.valueOf(si.getLongitude()));
row.getCustomElements()。setValueLocal(latitude,String.valueOf(si.getLatitude()));
row.getCustomElements()。setValueLocal(last_maint,String.valueOf(si.getLast()));
row.getCustomElements()。setValueLocal(inst_date,String.valueOf(si.getInst()));

row = service.insert(listFeedUrl,row); //在这里抛出异常

return true;
}


解决方案

就像是一个让Google识别谁在阅读或谁正在写电子表格的关键,如果您没有正确的访问级别,它将不会允许。即使您使用浏览器打开Goog​​le电子表格,浏览器也会从Google身份提供商生成OAuth令牌,并使用该令牌检查您的访问级别。

更新在这里,如果您看到我的浏览器如何处理对Google电子表格的请求,它将首先重定向到身份提供商。大多数情况下,你需要模拟它才能工作。




I've searched a lot of websites about how to do that using only the spreadsheet key, but with no success. I can retrieve it, get all the data I want, but I can't append a new row to it.

I've already published my spreadsheet to the web and made it public but I keep getting " com.google.gdata.util.ServiceException: Method Not Allowed".

That's how I'm trying to do it:

SpreadsheetService service =
            new SpreadsheetService("MySpreadsheetIntegration-v1");

        try {

        URL url = FeedURLFactory.getDefault().getWorksheetFeedUrl(SpreadsheetRequest.KEY, "public", "full"); //KEY = "1cenwTRlrGMzMTufkK27IIgAHvEGwVKR9Yr59Qako3u0";

        WorksheetFeed worksheetFeed = service.getFeed(url, WorksheetFeed.class);
        List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
        WorksheetEntry worksheet = worksheets.get(0);

        URL listFeedUrl = worksheet.getListFeedUrl();

        ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
        List<ListEntry> list = listFeed.getEntries();

       //Checking all the entries, works like a charm
        for (ListEntry row : list) {
            Log.i("INSERT",row.getTitle().getPlainText() + "\t"
                    + row.getPlainTextContent());
        }

        ListEntry row = new ListEntry();

        row.getCustomElements().setValueLocal("id", "21");
        row.getCustomElements().setValueLocal("type", si.getType().toString());
        row.getCustomElements().setValueLocal("longitude", String.valueOf(si.getLongitude()));
        row.getCustomElements().setValueLocal("latitude", String.valueOf(si.getLatitude()));
        row.getCustomElements().setValueLocal("last_maint", String.valueOf(si.getLast()));
        row.getCustomElements().setValueLocal("inst_date", String.valueOf(si.getInst()));

        row = service.insert(listFeedUrl, row); //Exception is thrown here

        return true;
    }

解决方案

Answer is No. OAuth token is like a key which allows Google to identify who is reading or who is writing to the spreadsheet and it won't allow if you don't have the correct access level. Even when you open Google spreadsheet with your browser the browser will generate an OAuth token from the Google identity provider and use that token to check whether your access level.

Update Here if you see how my browser handle the request done to the google spread sheet it will first redirect to the identity provider. Most of the time you need to simulate that in order to work.

这篇关于有没有办法在没有使用java的OAuth的情况下在Google Spreadsheet上添加一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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