title: How to upload a Google Docs document in Haskell?
body: <p>I want to create a Google Docs document from within Haskell, so basically I want to do in Haskell what this little C# program does (adapted from a Google sample program): </p>
  
  <pre><code>using Google.GData.Documents;
  using Google.GData.Client;
  
  namespace DocListUploader
  {
      public class GDocConsole
      {
          static void Main()
          {
              var user = "...";
              var passwd = "...";
              var file = "...";
  
              service = new DocumentsService("DocListUploader");
              service.setUserCredentials(user, passwd);
              service.UploadDocument(file, null);
          }
      }
  }
  </code></pre>
  
  <p>From the Google Docs API description <a href="https://developers.google.com/google-apps/documents-list/" rel="nofollow noreferrer">here</a>
   and this SO answer <a href="https://stackoverflow.com/questions/2704902/how-do-you-create-a-document-in-google-docs-programmatically">here</a> I understood it's "only" a matter of sending a couple of HTTP POSTs and getting the OAuth authentification done, but just how? Has anybody already done it and has some code samples for me...?</p>
  
  <p>EDIT: Still could not figure out how to use the oauth libraries, so I just wrote a little C# wrapper:</p>
  
  <pre><code>using Google.GData.Documents;
  using Google.GData.Client;
  
  public class GoogleDoc
  {
      public static int Upload(string user, string passwd, string file)
      {
          try
          {
              var service = new DocumentsService("DocListUploader");
              service.setUserCredentials(user, passwd);
              service.UploadDocument(file, null);
  
              return 0;
          }
          catch
          {
              return -1;
          }
      }
  }
  </code></pre>
  
  <p>and called this wrapper from Haskell via hs-dotnet:</p>
  
  <pre><code>module Upload where
  
  import NET
  
  upload :: String -&gt; String -&gt; String -&gt; IO (Int)
  upload user passed file = 
     invokeStatic "[GoogleDoc.dll]GoogleDoc" "Upload" (user, passed, file)
  
  testLocal :: IO ()
  testLocal = do
    let user = "..."
    let passwd = "..."
    let file = "..."
    returnCode &lt;- upload user passwd file
    putStrLn (show returnCode)
  </code></pre>