1

現在、Google API をテストしています。有望に思えますが、「単純な」問題で立ち往生しています。ローカル コピーを使用して既存のドキュメントを更新したいと考えています。

私の考えは、doc-downloadを使用して、すべてのGoogleドキュメントをフォルダーにダウンロードすることでした。それはうまくいきます。次回の実行時に日付を確認し、リモート ドキュメントの方が新しい場合は、もう一度取得します。ローカル ドキュメントの方が新しい場合は、それをアップロードして、現在のオンライン バージョンを置き換えます。

ドキュメントを置き換える関数が見つかりません。Upload(filename, doctitle) がありますが、これにより新しいドキュメントが作成されます。これが可能かどうかを知っている人はいますか?修正の方向に私を向けることができます. Atom フィードを分析する必要がありますか (ドキュメント コンテンツはその中のどこかにありますか..)。「ダウンロード/単語の変更/アップロード」はとても素敵に見えました:-)

クリス

興味のある人にとっては、API を使用するのは非常に簡単で便利です。これは短いWPFの例です(もちろん、資格情報はありません)

        var settings = new RequestSettings("GoogleDocumentsSample", _credentials);
        AllDocuments = new ObservableCollection<Document>();

        settings.AutoPaging = true;
        settings.PageSize = 10;

        service = new DocumentsService("DocListUploader");
        ((GDataRequestFactory)service.RequestFactory).KeepAlive = false;
        service.setUserCredentials(username, password);

        //force the service to authenticate
        var query = new DocumentsListQuery {NumberToRetrieve = 1};
        service.Query(query);



        var request = new DocumentsRequest(settings);


        Feed<Document> feed = request.GetEverything();
        // this takes care of paging the results in
        foreach (Document entry in feed.Entries)
        {
            AllDocuments.Add(entry);
            if (entry.Type == Document.DocumentType.Document)
            {
                var fI = new FileInfo(@"somepath" + entry.DocumentId + ".doc");

                if (!fI.Exists || fI.LastWriteTime < entry.Updated)
                {
                    Debug.WriteLine("Download doc " + entry.DocumentId);
                    var type = Document.DownloadType.doc;
                    Stream stream = request.Download(entry, type);

                    if (fI.Exists) fI.Delete();

                    Stream file = fI.OpenWrite();

                    int nBytes = 2048;
                    int count = 0;
                    Byte[] arr = new Byte[nBytes];

                    do
                    {
                        count = stream.Read(arr, 0, nBytes);
                        file.Write(arr, 0, count);

                    } while (count > 0);
                    file.Flush();
                    file.Close();

                    stream.Close();

                    fI.CreationTimeUtc = entry.Updated;
                    fI.LastWriteTimeUtc = entry.Updated;

                }
                else
                {
                    if (entry.Updated == fI.LastWriteTime)
                    {
                        Debug.WriteLine("Document up to date " + entry.DocumentId);
                    }
                    else
                    {
                        Debug.WriteLine(String.Format("Local version newer {0} [LOCAL {1}] [REMOTE {2}]", entry.DocumentId, fI.LastWriteTimeUtc, entry.Updated));
                        service.UploadDocument(fI.FullName, entry.Title);

                    }
                }

            }

        }
4

1 に答える 1

2

Docs API docs によると;)ドキュメントのコンテンツを置き換えることができます http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UpdatingContent

于 2009-11-18T22:59:22.230 に答える