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!
精彩评论