如何从Windows获取Watson的个性洞察?



个性洞察教程说使用以下 cURL 命令:

curl -X POST --user {username}:{password} 
--header "Content-Type: application/json" 
--data-binary "@{path_to_file}profile.json" 
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"

我翻译为:

curl -X POST --user myun:mypw 
--header "Content-Type: application/json" 
--data-binary "@C:mypathprofile.json" 
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"

我下载并安装了cURL,但我在PowerShell中不断收到这些可怕的错误:

At line:2 char:3
+ --header "Content-Type: application/json" 
+   ~
Missing expression after unary operator '--'.
At line:2 char:3
+ --header "Content-Type: application/json" 
+   ~~~~~~
Unexpected token 'header' in expression or statement.
At line:3 char:3
+ --header "Accept: text/csv" 
+   ~
Missing expression after unary operator '--'.
At line:3 char:3
+ --header "Accept: text/csv" 
+   ~~~~~~
Unexpected token 'header' in expression or statement.
At line:4 char:3
+ --data-binary "C:mypathprofile.json" 
+   ~
Missing expression after unary operator '--'.
At line:4 char:3
+ --data-binary "C:mypathprofile.json" 
+   ~~~~~~~~~~~
Unexpected token 'data-binary' in expression or statement.
At line:5 char:3
+ --output "C:profile.csv" 
+   ~
Missing expression after unary operator '--'.
At line:5 char:3
+ --output "C:profile.csv" 
+   ~~~~~~
Unexpected token 'output' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

这是我尝试过的:

  • myun:mypw放在双引号中
  • data-binary后删除与号
  • 符号
  • 谷歌搜索"表达式或语句中出现意外的令牌'标头'"。但这似乎是逐案处理的(这意味着这可能也是一个)
  • 我知道 windows 的 cURL 不喜欢单引号,但我在这里没有看到任何单引号,我不确定是否有任何其他可能影响这一点的特殊性。

PowerShell中的换行符不是通过转义,而是通过反勾号'转义。因此,如果要在PowerShell中执行此命令,请完全避免转义换行符或使用反引号:

curl -X POST --user myun:mypw `
--header "Content-Type: application/json" `
--data-binary "@C:mypathprofile.json" `
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"

不过,避免背勾会更好,因为它们很难阅读。

最新更新