AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi Microsoft Translator Text API v3.0

Microsoft Translator Text API v3.0

Ein Thema von psycodad · begonnen am 13. Feb 2019 · letzter Beitrag vom 18. Feb 2019
Antwort Antwort
psycodad

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

Microsoft Translator Text API v3.0

  Alt 13. Feb 2019, 09:34
Hallo zusammen,

Ich probiere jetzt schon seit einer geraumen Weile mit dem RestDebugger die neue Translator API von Microsoft (Version 3.0) anzusprechen. Der Grund dafür ist dass die alte API Version 2.0 per 30. April 2019 eingestellt wird.

https://docs.microsoft.com/en-us/azu...v3-0-reference

Es gelingt mir einfach nicht, die API zu einem Resultat zu bewegen. Ich kriege nur immer die Fehlermeldung:
"One of the request inputs is not valid"

Im Anhang seht ihr wie ich den RestDebugger konfiguriert habe. Ich glaube alles richtig zu machen. Kann mir dasy jemand weiterhelfen?
Miniaturansicht angehängter Grafiken
2019-02-13_09-31-46.png   2019-02-13_09-28-55.png  

Geändert von psycodad (13. Feb 2019 um 09:39 Uhr)
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.093 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Microsoft Translator Text API v3.0

  Alt 13. Feb 2019, 09:47
(ignoriert mich)

Geändert von Der schöne Günther (13. Feb 2019 um 09:48 Uhr) Grund: oops
  Mit Zitat antworten Zitat
TigerLilly

Registriert seit: 24. Mai 2017
Ort: Wien, Österreich
1.172 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 07:58
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.
  Mit Zitat antworten Zitat
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, 11: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
psycodad

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

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 11:13
Man kann sich mit drei verschiedenen Methoden authentifizieren. ICh nutze die Methode mit Ocp-Apim-Subscription-Key im request header. Das funktioniert tiptop mit dem c# demo projekt. Es kann also nicht daran liegen. Wenn ich den header Eintrag entferne kriege ich ein "The request is not authorized because credentials are missing or invalid".

Es muss damit zu tun haben wie der REstdebugger (TRestRequest) den request content behandelt. Man muss da ein json array im content mitgeben. ich habe den json array von der microsoft translator api Website kopiert und wie gesagt funktioniert dieser im c# projekt:
[{"Text":"I would really like to drive your car around the block a few times."}]

Ich steh auf dem Schlauch.
  Mit Zitat antworten Zitat
Benutzerbild von sh17
sh17

Registriert seit: 26. Okt 2005
Ort: Radebeul
1.592 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 11:46
Crosspost

https://en.delphipraxis.net/topic/69...-text-api-v30/
Sven Harazim
--
  Mit Zitat antworten Zitat
psycodad

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

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 12:32
Ah, ich dachte es sei besser wenn ich es in beiden Foren schreibe, mal auf Englisch und mal Deutsch. Ist das nicht erlaubt?
  Mit Zitat antworten Zitat
Benutzerbild von sh17
sh17

Registriert seit: 26. Okt 2005
Ort: Radebeul
1.592 Beiträge
 
Delphi 11 Alexandria
 
#8

AW: Microsoft Translator Text API v3.0

  Alt 14. Feb 2019, 12:55
Doch, aber es ist immer gut wenn ein Thread vom anderen weiß, sodass nicht doppelt nach einer Lösung gesucht wird, bzw der eine Thread vom anderen profitiert.
Sven Harazim
--
  Mit Zitat antworten Zitat
psycodad

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

AW: Microsoft Translator Text API v3.0

  Alt 15. Feb 2019, 16:16
Found the solution:

- Empty TRestRequest.Ressource property

- Remove all parameters except the Header with the subscription key

- Use following BaseURL instead: https://api-eur.cognitive.microsoftt...m=en&amp;to=de

Now all works like expected. But i even do not know why i should not use the TRestRequest.Params and the Ressource property instead of the URL parameters...
  Mit Zitat antworten Zitat
psycodad

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

AW: Microsoft Translator Text API v3.0

  Alt 18. Feb 2019, 14:56
Hier ein kleines Demo Projekt das den Aufruf der Microsoft Translator API V3.0 zeigt..
Angehängte Dateien
Dateityp: zip translation api.zip (7,2 KB, 31x aufgerufen)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz