小编Ric*_*ick的帖子

尝试使用gdata python库批量更新到Google电子表格

我一直试图弄清楚这一段时间,但似乎没有能够突破,所以希望有人在那之前做过这件事.

我的问题是我正在尝试使用gdata python客户端库批量更新google电子表格并通过oauth2进行身份验证.我在这里找到了一个如何使用gdata.spreadsheet.service模块进行批量更新的示例:https://code.google.com/p/gdata-python-client/wiki/UsingBatchOperations

但是,当通过oauth2进行身份验证时,这似乎不起作用,因此我不得不使用gdata.spreadsheets.client模块,而不是如本文所述:https://code.google.com/p/gdata-python-client/问题/细节?ID = 549

使用gdata.spreadsheets.client模块可用于身份验证和更新工作表,但批处理命令似乎不起作用.下面是我最近的代码变体,它是我最接近的.它似乎工作但工作表没有更新,返回的batch_status是:'批量不支持插入'.(注意:我确实尝试在注释掉的代码中修改CellEntries的batch_operation和batch_id参数,但这也不起作用.)

感谢您的任何帮助,您可以提供.

    import gdata
    import gdata.gauth
    import gdata.service
    import gdata.spreadsheets
    import gdata.spreadsheets.client
    import gdata.spreadsheets.data

    token = gdata.gauth.OAuth2Token(client_id=Client_id,client_secret=Client_secret,scope=Scope,
                                        access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN,
                                        user_agent=User_agent)

    client = gdata.spreadsheets.client.SpreadsheetsClient()
    token.authorize(client)
    range = "D6:D13"

    cellq = gdata.spreadsheets.client.CellQuery(range=range, return_empty='true')
    cells = client.GetCells(file_id, 'od6', q=cellq)

    objData = gdata.spreadsheets.data
    batch = objData.BuildBatchCellsUpdate(file_id, 'od6')

    n = 1
    for cell in cells.entry:
        cell.cell.input_value = str(n)
        batch.add_batch_entry(cell, cell.id.text, batch_id_string=cell.title.text, operation_string='update')
        n = n + 1
    client.batch(batch, force=True)
Run Code Online (Sandbox Code Playgroud)

python gdata oauth-2.0

7
推荐指数
0
解决办法
1212
查看次数

标签 统计

gdata ×1

oauth-2.0 ×1

python ×1