Einzelnen Beitrag anzeigen

psycodad

Registriert seit: 8. Feb 2005
Ort: Embrach (CH)
40 Beiträge
 
Delphi 10.3 Rio
 
#4

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 10:06
Meines Wissens musst du dich zuerst mit Ocp-Apim-Subscription-Key authentifizieren (liefert ein Token zurück) und mit diesem Token musst du die folgenden Aufrufe autorisieren. Das Token ist 10 Minuten gültig, dann musst du eines neues beantragen.
Microsoft says:

Zitat:
Authentication

Subscribe to Translator Text API or Cognitive Services all-in-one in Microsoft Cognitive Services, and use your subscription key (available in the Azure portal) to authenticate.

There are three headers that you can use to authenticate your subscription. This table provides describes how each is used:

Ocp-Apim-Subscription-Key Use with Cognitive Services subscription if you are passing your secret key.
The value is the Azure secret key for your subscription to Translator Text API.

Authorization Use with Cognitive Services subscription if you are passing an authentication token.
The value is the Bearer token: Bearer <token>.

Ocp-Apim-Subscription-Region Use with Cognitive Services all-in-one subscription if you are passing an all-in-one secret key.
The value is the region of the all-in-one subscription. This value is optional when not using an all-in-one subscription.
Secret key

The first option is to authenticate using the Ocp-Apim-Subscription-Key header. Simply add the Ocp-Apim-Subscription-Key: <YOUR_SECRET_KEY> header to your request.
I use the first way with the Ocp-Apim-Subscription-Key in the request header. That works well, because if i remove the Ocp-Apim-Subscription-Key header i get the following answer:
"The request is not authorized because credentials are missing or invalid"

So authorisation works in my opinion. Btw in the c# demo project that works well too.

I assume that the problem comes from the request body parameter:
[{"Text":"I would really like to drive your car around the block a few times."}]

in the request content body there should be a json array with a "Text" property. I copied the json above from the microsoft translator API website. In the c# project that works well. It must have something to do how the RestDebugger (TRestRequest) handles the request.content.
  Mit Zitat antworten Zitat