我想從內哈斯克爾創建一個谷歌文檔文件,所以基本上我想在Haskell做這個小C#程序不會(改編自谷歌示例程序):如何在Haskell中上傳Google文檔?
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);
}
}
}
從谷歌文檔API說明here 和這個SO回答here我知道這只是一個發送幾個HTTP POST並完成OAuth認證的問題,但是這只是一個問題。有沒有人已經完成了它,併爲我提供了一些代碼示例...?
編輯:還是沒能弄清楚如何使用OAuth庫,所以我就寫了一個小C#包裝:
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;
}
}
}
,並呼籲通過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)
雖然我不熟悉Google Docs API,但您應該查看[Hackage上的http包](http://hackage.haskell.org/package/HTTP)。 – 2012-03-23 23:16:03