我正在尝试使用Gogol执行Google自定义搜索。我有下面的代码,但它不能编译,我不明白错误信息告诉我为什么。如何让程序编译以便Google搜索起作用?如何在Haskell中执行Google自定义搜索(使用gogol)?
searchCoversCustomly :: Text -> IO Search
searchCoversCustomly phrase = do
env <- G.newEnv -- create google environment
rVols <- G.runResourceT . G.runGoogle env $ do -- run request
let request = (cSEList phrase) -- request construction
& (cselCx .~ Just cx)
. (cselNum .~ 3)
. (cselSearchType .~ Just Image)
G.send request
return rVols
where cx = "..."
这将导致以下错误消息:
src/GoogleInteraction.hs:56:12: error:
• Ambiguous type variable ‘s0’ arising from a use of ‘G.newEnv’
prevents the constraint ‘(G.AllowScopes s0)’ from being solved.
Probable fix: use a type annotation to specify what ‘s0’ should be.
These potential instances exist:
instance G.AllowScopes '[]
-- Defined in ‘Network.Google.Auth.Scope’
...plus one instance involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block: env <- G.newEnv
In the expression:
do { env <- G.newEnv;
rVols <- G.runResourceT . G.runGoogle env
$ do { let ...;
G.send request };
return rVols }
我对谷歌图书还与果戈理工作代码工作片段。不同之处在于我在那里提供了一个相关的范围,如Gogol文档instruct。
对于在gogol-books' docs中记载的BooksScope的书籍,但在gogol-customsearch的文档中没有提及此范围。
如何让程序编译以便Google搜索起作用?谢谢!
===编辑:包括
• Couldn't match expected type ‘IO a0’
with actual type ‘k10 '[] -> k10 '[]’
• Probable cause: ‘G.forbid’ is applied to too few arguments
In the second argument of ‘(<$>)’, namely ‘G.forbid’
它抱怨的类型变量代表'凭据'(不管那是..我对谷歌API一无所知)。你需要在某处指定类型,或许用'env :: Env Something < - ...'。我不知道'Something'应该是什么,但我会假设你知道你打算使用哪个'凭证'。或者,使用'newEnvWith',它允许您指定[credentials](https://hackage.haskell.org/package/gogol-0.1.1/docs/Network-Google-Auth.html#t:Credentials)价值水平。 – user2407038
感谢您的解释。如果我正确理解Google自定义搜索,那么您使用附加到URL的key = ... keyvalue-pair进行身份验证。 我在链接凭证文档中看不到Key类型,所以也许这样做不可能? – Arthur