Google文档列表API“创建或上传电子表格”中的说明不明确

时间:2013-10-01 16:52:51

标签: android google-sheets google-docs google-docs-api google-spreadsheet-api

尝试通过我的Android应用创建电子表格。到目前为止,我只是成功创建了一个空文本文档。 Google的电子表格API 指示我关注 Google文档列表API ,以便在 Google云端硬盘中创建电子表格文档。在 Google文档列表API 中,它说:

  

要创建新的空电子表格,请按照中的说明操作   Creating a new document or file with metadata only。这样做时,请使用   类别术语http://schemas.google.com/docs/2007#spreadsheet

在上面的链接中,我找到了下一个 .NET代码

using System;
using Google.GData.Client;
using Google.GData.Documents;

namespace MyDocumentsListIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");

      // TODO: Authorize the service object for a specific user (see Authorizing requests)

      // Instantiate a DocumentEntry object to be inserted.
      DocumentEntry entry = new DocumentEntry();

      // Set the document title
      entry.Title.Text = "Legal Contract";

      // Add the document category
      entry.Categories.Add(DocumentEntry.DOCUMENT_CATEGORY);

      // Make a request to the API and create the document.
      DocumentEntry newEntry = service.Insert(
          DocumentsListQuery.documentsBaseUri, entry);
    }
  }
}

我已使用此代码尝试创建电子表格,但只有第三种变体有效(使用 DocsService ,而不添加 Category 并使用 feedUrl 网址对象)。

这是我的工作代码的一部分(当用户点击按钮时调用upload()):

private void upload() {
        SpreadSheetAsyncTask sprdSheetAsyncTsk = new SpreadSheetAsyncTask();

        sprdSheetAsyncTsk.execute();

    }

    public class SpreadSheetAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            spreadSheetService = new SpreadsheetService("Salary_Calculator");
            docService = new DocsService("Salary_Calculator");
            try {

                spreadSheetService.setUserCredentials(USERNAME, PASSWORD);
                docService.setUserCredentials(USERNAME, PASSWORD);

                URL feedUrl = new URL(
                        "https://docs.google.com/feeds/default/private/full/");
                URL tmpFeedUrl = new URL(
                        "https://spreadsheets.google.com/feeds/worksheets/key/private/full");

                DocumentEntry entry = new DocumentEntry();

                Calendar timeRightNow = GregorianCalendar.getInstance();

                entry.setTitle(new PlainTextConstruct(
                        "Salary Calculator Spreadsheet "
                                + timeRightNow.get(Calendar.DAY_OF_MONTH) + "/"
                                + (timeRightNow.get(Calendar.MONTH) + 1) + "/"
                                + timeRightNow.get(Calendar.YEAR)));

//              Category object = new Category("spreadsheet",
//                      "http://schemas.google.com/docs/2007#spreadsheet");
//              
//
//              entry.getCategories().add(object);

                /*
                 * TODO TEST AREA
                 */

                entry = docService.insert(feedUrl, entry);
                /*
                 * TODO TEST AREA
                 */
            } catch (AuthenticationException e) {
                cancel(true);
                loginDialog("Wrong username or password");
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            } catch (ServiceException e) {
                cancel(true);
                loginDialog("Wrong username or password");
            } catch (Exception e) {
                loginDialog("Wrong username or password");
            }

            return null;
        }
    }

非工作代码使用上面的类别对象 object (如代码注释中所示)并使用entry = spreadSheetService.insert(feedUrl, entry);

我的问题是 - 当他们写use a category term of http://schemas.google.com/docs/2007#spreadsheet时,他们希望我做什么?

0 个答案:

没有答案