{"id":262,"date":"2014-03-16T19:15:23","date_gmt":"2014-03-16T09:15:23","guid":{"rendered":"http:\/\/www.docx4java.org\/blog\/?p=262"},"modified":"2014-03-16T19:15:23","modified_gmt":"2014-03-16T09:15:23","slug":"docx4j-and-google-drive","status":"publish","type":"post","link":"https:\/\/www.docx4java.org\/blog\/2014\/03\/docx4j-and-google-drive\/","title":{"rendered":"docx4j and Google Drive"},"content":{"rendered":"<p>Given the news this week about Google lowering prices per GB on Google Drive, I thought it would be timely to explore interop with docx4j.<\/p>\n<p>https:\/\/github.com\/plutext\/docx4j-cloud-GoogleDrive is a small project which demonstrates:<\/p>\n<div id=\"LC20\">\n<ul>\n<li><a href=\"https:\/\/github.com\/plutext\/docx4j-cloud-GoogleDrive\/blob\/master\/src\/main\/java\/Docx4jUploadToGoogleDrive.java\">Upload a wordMLPackage<\/a> (or presentationML or spreadsheetML pkg) to Google Drive as a docx<\/li>\n<li><a href=\"https:\/\/github.com\/plutext\/docx4j-cloud-GoogleDrive\/blob\/master\/src\/main\/java\/GoogleDriveDownloadAsDocx.java\">Download a file<\/a> from Google Drive as a docx4j WordprocessingMLPackage<\/li>\n<li><a href=\"https:\/\/github.com\/plutext\/docx4j-cloud-GoogleDrive\/blob\/master\/src\/main\/java\/GoogleDriveConvertFromDocxTo.java\">Convert a WordprocessingMLPackage<\/a> to the specified output format, using Google Drive<\/li>\n<\/ul>\n<\/div>\n<div id=\"LC20\">Clone the project, and set it up using Maven in your IDE. \u00a0I&#8217;m not going to tell you how to do that.<\/div>\n<div><\/div>\n<div><strong>Enabling the Drive API<\/strong><\/div>\n<div><\/div>\n<div>From there, it is fairly straightforward \u00a0(assuming you have a Google account); you just need to enable the Drive API: <a href=\"https:\/\/cloud.google.com\/console\/start\/api?id=drive&amp;credential=client_key\">set up a project and application in the Developers Console<\/a>:<\/div>\n<div>\n<ul>\n<li>press the red &#8220;CREATE NEW CLIENT ID&#8221; button, then choose application type &#8220;Installed Application&#8221;; I then chose subtype &#8220;Other&#8221;<\/li>\n<li>hit the &#8220;Download JSON&#8221; button; save it as <strong>client_secret.json <\/strong>in your project dir<\/li>\n<\/ul>\n<\/div>\n<p><strong>Run our code<\/strong><\/p>\n<p>OK, now try running Docx4jUploadToGoogleDrive<\/p>\n<p>It ought to say something like:<\/p>\n<blockquote>\n<div id=\"_mcePaste\">Please open the following URL in your browser then type the authorization code:<\/div>\n<div id=\"_mcePaste\">https:\/\/accounts.google.com\/o\/oauth2\/auth?access_type=online&amp;client_id=622239&#8230;<\/div>\n<\/blockquote>\n<p>Paste the auth code into your IDE&#8217;s console (System.in, probably the same place which displayed the above message) then press enter. \u00a0If you aren&#8217;t logged into your Google account in your browser, its at this point that you&#8217;ll be asked to log in.<\/p>\n<p>The code will create a new docx file, and after uploading it, if successful, report the File ID allocated by Google Drive:<\/p>\n<blockquote><p>File ID: 0CyHdofN18p16OF9YWWNFUFdmTjg<\/p><\/blockquote>\n<p>The other 2 samples require you to provide an auth code the same way (each time you run them). \u00a0Obviously, you&#8217;d be more sophisticated than this in a production application. \u00a0See further\u00a0<a href=\"https:\/\/developers.google.com\/drive\/web\/about-auth\">https:\/\/developers.google.com\/drive\/web\/about-auth<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given the news this week about Google lowering prices per GB on Google Drive, I thought it would be timely to explore interop with docx4j. https:\/\/github.com\/plutext\/docx4j-cloud-GoogleDrive is a small project which demonstrates: Upload a wordMLPackage (or presentationML or spreadsheetML pkg) to Google Drive as a docx Download a file from Google Drive as a docx4j [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":2,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":264,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions\/264"}],"wp:attachment":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}