2

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):

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);
        }
    }
}

From the Google Docs API description here and this SO answer here 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...?

EDIT: Still could not figure out how to use the oauth libraries, so I just wrote a little C# wrapper:

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;
        }
    }
}

and called this wrapper from Haskell via hs-dotnet:

module Upload where

import NET

upload :: String -> String -> String -> 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 <- upload user passwd file
  putStrLn (show returnCode)
Community
  • 1
  • 1
martingw
  • 4,153
  • 3
  • 21
  • 26
  • 1
    Although I'm not familiar with the Google Docs API, you should probably check out the [http package on Hackage](http://hackage.haskell.org/package/HTTP). – Ptharien's Flame Mar 23 '12 at 23:16

1 Answers1

4

You can use the haskell-oauth library to do the oauth and to upload the documentation, like mentioned already, you can try the http package from Haskell.

Gangadhar
  • 1,893
  • 9
  • 9
  • Thanks! I can't get haskell-oauth to run though, it seems like it's not so easy to install curl on Windows. There's also authenticate-oauth, which runs fine, but I can't figure out what I need to do in what order. An example would be great... – martingw Mar 24 '12 at 22:41
  • The factual-api package represents an example of usage for hoauth. http://hackage.haskell.org/packages/archive/factual-api/0.6.1/doc/html/src/Network-Factual-API.html – T_S_ Feb 05 '13 at 00:26