需要从我的应用程序将文件上传到google文档,并存储对已上传文件的引用 [英] Need to upload files to google docs from my application and store reference to the uploaded file

查看:77
本文介绍了需要从我的应用程序将文件上传到google文档,并存储对已上传文件的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于Google应用程序的基本系统.就像我先前定义的那样,我正在构建一个简单的订购系统,并向所下的每个订单附加一个文件或文档.我希望能够进行设置,以便将我上传的任何文件都上传到google docs中,并且我能够以某种方式维护我自己的应用程序对该文件的引用,即这些文件与该文件的顺序有关.我的应用程序希望基于Google应用程序,而我正在构建它,以便以后部署到云中时使用.我该如何开始呢?我需要做什么?我已经可以使用和应用可以使用的小部件了吗,还是需要为此创建自己的自定义解决方案?

我正在使用Php MySQL.

解决方案

您所描述的实际上很容易做到.您需要使用 Google文档列表数据API (DocsList API).该API用于在Google文档中创建(上传),检索,更新和删除文档.

具体来说,由于您使用的是PHP,因此您将需要对DocsList API使用PHP客户端库.这是在此处记录的.确保阅读该文档的入门部分,因为它列举了设置 Zend Framework 的重要步骤,该文档捆绑了DocsList PHP客户端库. /p>

假设您正在创建文字处理文档(而不是电子表格或演示文稿),则上传文档所需的代码很简单.

// Use ClientLogin to authenticate to Google Docs
$username = 'user@gmail.com';
$password = 'myPassword';
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME; 
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($username, $password,
    $service);
$docs = new Zend_Gdata_Docs($httpClient);

// Actually upload the file, the second parameter here is the document title
$newDocumentEntry = $docs->uploadFile('test.txt', 'order-123456',
    'text/plain', Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);

您提到您还希望将对这些文档的引用存储在系统中.为此,只需为每个文档指定一个唯一的标题(如"order-123456".)

接下来,要获取存储的文档,请使用以下代码:

$docsQuery = new Zend_Gdata_Docs_Query();
$docsQuery->setTitle("order-123456");
$docsQuery->setTitleExact(true);
$feed = $docs->getDocumentListFeed($docsQuery);
foreach ($feed->entries as $entry) {
  // ... every $entry is an individual document found in the search ...
}

请注意,此示例使用ClientLogin,这需要原始用户名和密码.一种更好但不太简单的身份验证方法是使用OAuth/AuthSub .另请注意,目前仅针对DocsList API的1.0版更新了PHP客户端库,已弃用.客户端库的更新版本即将发布,以支持API的较新版本.有关更多信息,请参见 Google文档列表数据API开发人员指南.祝你好运!

I'm working on a basic google applications based system. Like I earlier defined I'm building a simple ordering system and to each order placed I attach a file or document. I would like to be able to set it such that whatever file I upload is uploaded into google docs and I somehow am able to maintain a reference to that file from my own application i.e these files are concerned with such and such order. My application is google application based hopefully and I'm building it to be such for later on deployment into the cloud. How do I start on this and what do I need to do? Are there already working widgets I can use and apply or would I need to create my own customised solution for this?

I'm working in Php MySQL.

解决方案

What you've described is actually pretty easy to do. You need to use the Google Documents List Data API (DocsList API.) This API is used to create (upload), retrieve, update, and delete documents in Google Docs.

Specifically, since you're using PHP, you'll want to use the PHP client library for the DocsList API. This is documented here. Make sure to read the Getting Started portion of that document, as it enumerates important steps on setting up the Zend Framework, with which the DocsList PHP client library comes bundled.

Assuming you're creating word processing docs (as opposed to spreadsheets or presentations,) the code you need to upload a document is straight forward.

// Use ClientLogin to authenticate to Google Docs
$username = 'user@gmail.com';
$password = 'myPassword';
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME; 
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($username, $password,
    $service);
$docs = new Zend_Gdata_Docs($httpClient);

// Actually upload the file, the second parameter here is the document title
$newDocumentEntry = $docs->uploadFile('test.txt', 'order-123456',
    'text/plain', Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);

You mentioned you'd also like to store references to these documents in your system. To do this, simply give each document a unique title (something like "order-123456".)

Next, to fetch the stored documents, use the following code:

$docsQuery = new Zend_Gdata_Docs_Query();
$docsQuery->setTitle("order-123456");
$docsQuery->setTitleExact(true);
$feed = $docs->getDocumentListFeed($docsQuery);
foreach ($feed->entries as $entry) {
  // ... every $entry is an individual document found in the search ...
}

Note that this example uses ClientLogin, which requires a raw username and password. A better, but less simple way to authenticate is to use OAuth/AuthSub. Also note that the PHP client library is only updated for version 1.0 of the DocsList API at the moment, which is deprecated. There should be an updated release of the client library soon to support newer versions of the API. For more information, see the Google Documents List Data API Developer's Guide. Good luck!

这篇关于需要从我的应用程序将文件上传到google文档,并存储对已上传文件的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆