使用 Google 文档 API

发布于 2024-12-09 21:18:27 字数 414 浏览 0 评论 0原文

我想知道如何将远程文档上传到 Google 文档,以及如何通过 Google 文档 API 使用 Google 文档查看该文档。

当我上传文件时,是否会回复 docid?这样我就可以在上传到我的帐户后使用它在线查看文档。

打开我的帐户中的文档之一

例如,我可以使用 docid https://docs.google.com/Doc?docid=0AdmWTTLTOoWVBZGd3ZDdtZmhfMGZ3czNrNmho

这可以在 PHP 中实现吗?我听说它不再受支持。与 C# 相比,我更喜欢 PHP,但如果不支持 PHP,我可以使用 C#。

I want to know how to upload a remote document to Google Docs, and to be able to view that document using Google Docs by using the Google Docs API.

When I upload a file, does is respond with a docid? So that I can use it to view the document online after uploading in to my account.

For instance I can open one of the documents in my account by using the docid

https://docs.google.com/Doc?docid=0AdmWTLTOoWVBZGd3ZDdtZmhfMGZ3czNrNmho

Will this be implementable in PHP? I heard its no longer supported. I will prefer PHP over C#, but if PHP is not supported I can use C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2024-12-16 21:18:27

您必须使用以下代码将文件下载到本地。

var request = new DocumentsRequest(settings);
request.BaseUri = "https://docs.google.com/feeds/default/private/full/folder" + folderResourceId + "/contents";
Feed<Document> feed = request.GetEverything();

foreach (Document entry in feed.Entries)
{
    if (entry.Title == fileName)
    {
        var fI = new FileInfo(uploadpath + entry.Title);
        Stream stream = request.Download(entry, "");
        arr = Read(stream);
        stream.Close();
        break;
     }
}

private Byte[] Read(Stream stream)
{
    //long originalPosition = stream.Position;
    //stream.Position = 0;

    try
    {
        Byte[] readBuffer = new Byte[4096];

        int totalBytesRead = 0;
        int bytesRead;

        while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
        {
            totalBytesRead += bytesRead;

            if (totalBytesRead == readBuffer.Length)
            {
                int nextByte = stream.ReadByte();
                if (nextByte != -1)
                {
                    Byte[] temp = new Byte[readBuffer.Length * 2];
                    Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
                    Buffer.SetByte(temp, totalBytesRead, (Byte)nextByte);
                    readBuffer = temp;
                    totalBytesRead++;
                }
            }
        }

        Byte[] buffer = readBuffer;
        if (readBuffer.Length != totalBytesRead)
        {
            buffer = new Byte[totalBytesRead];
            Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
        }
        return buffer;
    }
    finally
    {
        //stream.Position = originalPosition;
    }
}

下载文件后将其保存到本地系统并使用asp.net显示

You have to download the file local using the following code.

var request = new DocumentsRequest(settings);
request.BaseUri = "https://docs.google.com/feeds/default/private/full/folder" + folderResourceId + "/contents";
Feed<Document> feed = request.GetEverything();

foreach (Document entry in feed.Entries)
{
    if (entry.Title == fileName)
    {
        var fI = new FileInfo(uploadpath + entry.Title);
        Stream stream = request.Download(entry, "");
        arr = Read(stream);
        stream.Close();
        break;
     }
}

private Byte[] Read(Stream stream)
{
    //long originalPosition = stream.Position;
    //stream.Position = 0;

    try
    {
        Byte[] readBuffer = new Byte[4096];

        int totalBytesRead = 0;
        int bytesRead;

        while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
        {
            totalBytesRead += bytesRead;

            if (totalBytesRead == readBuffer.Length)
            {
                int nextByte = stream.ReadByte();
                if (nextByte != -1)
                {
                    Byte[] temp = new Byte[readBuffer.Length * 2];
                    Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
                    Buffer.SetByte(temp, totalBytesRead, (Byte)nextByte);
                    readBuffer = temp;
                    totalBytesRead++;
                }
            }
        }

        Byte[] buffer = readBuffer;
        if (readBuffer.Length != totalBytesRead)
        {
            buffer = new Byte[totalBytesRead];
            Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
        }
        return buffer;
    }
    finally
    {
        //stream.Position = originalPosition;
    }
}

After download the file save it to local system and display using asp.net

空城缀染半城烟沙 2024-12-16 21:18:27

第 1 步:使用 documentCreate 方法以您选择的编程语言创建新的 Google 文档:
参考:文档创建
(此参考描述了原始 http 请求,有多种语言的 API。)

第 2 步:读取输入文件的文本,并使用 insertText 方法将文本插入到 Google 文档中:
golang
javascript

第 3 步:向 google 添加样式元素文档,如果您想让文档看起来漂亮的话。

Step 1: create a new google document in the programming language of your choice using the documentCreate method:
reference: document create
(This reference describes the raw http request, there are APIS for numerous languages.)

Step 2: read the text of your input file and insert the text into the Google document with the insertText method:
golang
javascript

Step 3: add styling elements to the google document, if you care to make the document look pretty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文