Salve a tutti,
Oggi ho deciso di voler sviluppare un traduttore personalizzato in VisualBasic.Net 2008
Dopo essermi documentato decisi di svilupparlo scegliendo l'API di GoogleTranslate; qindi ho provveduto a scaricare la versione 0.4 alpha dal sito code.google.com/... .
Dopo aver caricato nei riferimenti del mio progetto le dll GoogleTranslateAPI e Newtonsoft.Json contenute nella cartella DotNet in un Button ho scritto il seguente codice:
( Textbox5.Text è il Textbox da tradurre mentre Textbox3.Text è il Textbox tradotto.)
codice:
If Me.TextBox5.Text = String.Empty Then Return
Me.TextBox3.Text = ""
Dim Tilate As New Google.API.Translate.TranslateClient("")
Me.TextBox3.Text = Tilate.TranslateAndDetect(Me.TextBox5.Text, "fr", "")
End If
La compilazione non mi trova errori. ma appena scrivo un testo nel Textbox5 e premo il Button, Visual Studio mi evidenzia la riga:
codice:
Me.TextBox3.Text = Tilate.TranslateAndDetect(Me.TextBox5.Text, "fr", "")
e mi dice: [response status:403]Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors.
se volete dare uno sguardo ai dettagli dell'eccezione:
codice:
Google.API.GoogleServiceException non è stata gestita
Message=[response status:403]Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors
_ResponseDetails=Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors
_ResponseStatus=403
_Source=GoogleTranslateAPI
_StackTrace:
_ _ _ in Google.API.RequestUtility.Deserialize[T](String text)
_ _ _ in Google.API.RequestUtility.GetResponseData[T](IRequestInfo requestInfo)
_ _ _ in Google.API.GoogleClient.GetResponseData[T](GoogleRequest request)
_ _ _ in Google.API.Translate.TranslateClient.NativeTranslate(String text, String from, String to, String format)
_ _ _ in Google.API.Translate.TranslateClient.TranslateAndDetect(String text, String to, String format, String& from)
_ _ _ in Google.API.Translate.TranslateClient.TranslateAndDetect(String text, String to, String& from)
_ _ _ in WindowsApplication1.Form2.TextBox2_KeyDown(Object sender, KeyEventArgs e) in C:\Documents and Settings\DANIELE\documenti\visual studio 2010\Projects\WindowsApplication5\WindowsApplication5\Form2.vb:riga 95
_ _ _ in System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
_ _ _ in System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
_ _ _ in System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
_ _ _ in System.Windows.Forms.Control.WndProc(Message& m)
_ _ _ in System.Windows.Forms.TextBoxBase.WndProc(Message& m)
_ _ _ in System.Windows.Forms.TextBox.WndProc(Message& m)
_ _ _ in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
_ _ _ in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
_ _ _ in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
_ _ _ in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
_ _ _ in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
_ _ _ in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
_ _ _ in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
_ _ _ in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
_ _ _ in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
_ _ _ in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
_ _ _ in WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81
_ _ _ in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
_ _ _ in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
_ _ _ in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
_ _ _ in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
_ _ _ in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
_ _ _ in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
_ _ _ in System.Threading.ThreadHelper.ThreadStart()
_InnerException:
Grazie Infinite!!