Haskell:使用“fb”包删除Facebook Post

时间:2014-08-04 22:31:53

标签: facebook facebook-graph-api haskell

我正在尝试使用fb包中的deleteObject删除Facebook帖子。

我的以下方法实际上删除了帖子:

delete :: String -> IO ()
delete fbid = withManager $ \mgr -> FB.runFacebookT credentials mgr $ do
  del <- FB.deleteObject (T.pack fbid) [] userToken
  liftIO $ print (del :: Bool)

不幸的是,结果值无法正确解析,但会引发以下异常:

*** Exception: ParseError {errorContexts = [], errorMessage = "Failed reading: satisfy", errorPosition = 1:1}

Facebook-API的实际结果只是true

关于如何防止这种情况的任何想法?或者也许还有其他方法来检测请求是否有效?

1 个答案:

答案 0 :(得分:0)

在我看来,这是fb包中的一个错误。 deleteObject函数实现为

deleteObject = methodObject HT.methodDelete

methodObject method path query token =
  runResourceInFb $ do
    req <- fbreq path (Just token) query
    asJson =<< fbhttp req { H.method = method }

asJson = lift . asJsonHelper

asJsonHelper response = do
  val <- H.responseBody response C.$$+- C.sinkParser A.json'
  case A.fromJSON val of
    A.Success r -> return r
    A.Error str ->
        E.throw $ FbLibraryException $ T.concat
             [ "Facebook.Base.asJson: could not parse "
             , " Facebook's response as a JSON value ("
             , T.pack str, ")" ]

A.json'是用于JSON值的aeson解析器,但是作为function's documentation状态:

  

解析顶级JSON值。根据RFC 4627,它必须是对象或数组。

可以在GHCi中验证此行为:

Prelude Data.Attoparsec Data.Aeson> parse json' "true"
Fail "true" [] "Failed reading: satisfyElem"