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