![](/img/trans.png)
[英]issues with Calling watson API from a .net framework project. .net framework cannot refer to a .net core project
[英]how to call ibm watson api from .net core
我試圖調用watson個性洞察api,在環顧四周后,似乎解決方案是使.net等效於以下curl請求。 我對此很陌生,想知道我是否可以獲得指導或指向相關的教程。
curl -X POST -u "{username}:{password}"
--header "Content-Type: application/json"
--data-binary @profile
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
您可以使用Watson Developer Cloud .NET Standard SDK 。 使用NuGet安裝Personality Insights服務
Install-Package IBM.WatsonDeveloperCloud.PersonalityInsights -Pre
實例化服務
// create a Personality Insights Service instance
PersonalityInsightsService _personalityInsights = new PersonalityInsightsService();
// set the credentials
_personalityInsights.SetCredential("<username>", "<password>");
致電該服務
var results = _personalityInsights.GetProfile(ProfileOptions.CreateOptions()
.WithTextPlain()
.AsEnglish()
.AcceptJson()
.AcceptEnglishLanguage()
.WithBody("some text"));
在將來的版本中,您將能夠使用命名參數而不是構建選項來調用服務。
var results = _personalityInsights.GetProfile(
"<input>",
"<content-type>",
"<content-language>",
"<accept>",
"<accept-language>",
"<raw-scores>",
"<csv-headers>"
"<consumption-preferences>",
"<version>"
);
在這種情況下你使用curl來調用API嗎? 根據你的例子......
通過提供要使用的服務實例的服務憑據中提供的username
和password
來調用Personality Insights。 API使用HTTP
基本身份驗證。
用於驗證:
curl -u "{username}":"{password}"
"https://gateway.watsonplatform.net/personality-insights/api/v3/{method}"
Bluemix從所有請求中收集數據,並使用這些數據來改進Watson服務。
請求記錄:
curl -u "{username}":"{password}"
--header "X-Watson-Learning-Opt-Out: true"
"https://gateway.watsonplatform.net/personality-insights/api/v3/{method}"
調用和獲取響應的方法:
curl -X POST -u "{username}:{password}"
--header "Content-Type: application/json"
--data-binary @profile.json
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
IBM Watson API使用標准HTTP響應代碼來指示方法是否成功完成。
200級響應始終表示成功。
400級響應表明存在某種失敗。
500級響應通常表示內部系統錯誤。
從IBM開始查看此文檔進行開發,所有示例如何調用以及是否有錯誤的原因。 這用於驗證如何工作以及如何使用。
在這里演示,你可以根據需要從github派生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.