开发者

Using the Google Docs API

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#.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜