cannot get token

1,050 views
Skip to first unread message

Olexander Danchuk

unread,
Sep 8, 2012, 11:10:02 PM9/8/12
to microsoft-tran...@googlegroups.com
Hello Group,

I am trying to use library in Android project but it fails when I obtain token from my client id and secret

According to steps from msdn  I have created client Id and secret

then I have used  microsoft-translator-java-api library to translate

farther error investigation shows 400 error when app retrieves auth token

I didn't change microsoft-translator-java-api library 

Does anyone has any suggestions before I dig into the library?

Thanks in advance!

Olexander Danchuk

unread,
Sep 9, 2012, 12:17:02 AM9/9/12
to microsoft-tran...@googlegroups.com
Exception in thread "main" java.lang.Exception: [microsoft-translator-api] Error retrieving translation : Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
at com.memetix.mst.translate.Translate.execute(Translate.java:61)
at MainClass.main(MainClass.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1368)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1362)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1016)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:139)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
... 7 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:138)
... 9 more

Process finished with exit code 1


My best gues that I cannot use it from client side .. only from server side. Am I wrong

Jonathan

unread,
Sep 9, 2012, 10:46:04 AM9/9/12
to microsoft-tran...@googlegroups.com
Hello Olexander -

This has been a long outstanding issue using this library on Android 4.0. My problem with fixing it has been that I have been personally unable to reproduce it in an Android Virtual Device and I do not currently have access to hardware capable of running Android 4.0.

Unless somebody else can track this down in an actual environment where it is occurring, I don't see myself being able to fix this issue with any speed. 

Wish I had better news for you on that front.

-jonathan

Olexander Danchuk

unread,
Sep 9, 2012, 11:23:06 AM9/9/12
to microsoft-tran...@googlegroups.com
Hello Jonathan,

Thank you for the response but I also tried library in java application (desktop) and it has the same result
So I don't think it is related to Android at all

btw I am using android 2.2-2.4

One thing I don't understand

is "Redirect URI" field that is mandatory when you create/edit  application and I don't know what to put in it

If it helps I can give you all my credentials ( later when problem will be solved I can delete current and create new )
I have also noticed that even if I put invalid clientId/secret I have got  the same exception stack

Thank you for trying helping me, any clue?

Regards,
Oleksandr

Thank you for your time and I look forward to your mails

Olexander Danchuk

unread,
Sep 9, 2012, 12:08:32 PM9/9/12
to microsoft-tran...@googlegroups.com
I have figured this out 
Thanks again for you great contribution

Regards,
Oleksandr

Thank you for your time and I look forward to your mails


Akash Nidhi P S

unread,
Jul 13, 2013, 3:10:25 AM7/13/13
to microsoft-tran...@googlegroups.com
Hi can u please tell me what was reason for that error and how to overcome that, it wld be of great help.
Thank You

Jonathan Griggs

unread,
Jul 13, 2013, 3:31:48 AM7/13/13
to microsoft-tran...@googlegroups.com
Hi Akash. 

I cannot speak for how Olexander fixed this issue, but based on past experience, nearly every problem using the API arises from setting the clientId / clientSecret with incorrect values.  

You can see the values you should be using by visiting this link: https://datamarket.azure.com/developer/applications/ and clicking on "Edit" next to the name of your registered application. There you should find the two values "Client ID" and "Client Secret". 

Good luck!
-jonathan



--
You received this message because you are subscribed to the Google Groups "microsoft-translator-java-api" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microsoft-translator...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Hector Gallego

unread,
Jul 13, 2013, 1:02:17 PM7/13/13
to microsoft-tran...@googlegroups.com
Hi Jonathan

The error that shows Olexander is due, as you are saying, to a bad configuration of the pair clientid-clientsecret. It is a little confuse because in the begining of the registration, microsoft gives a pair that dont correspond with your app pair.

I am very grateful with your work. Thank you very much

Regards
To unsubscribe from this group and stop receiving emails from it, send an email to microsoft-translator-java-api+unsub...@googlegroups.com.

Olexander Danchuk

unread,
Jul 13, 2013, 3:41:47 PM7/13/13
to microsoft-tran...@googlegroups.com
This is an example how I am using it in my application:

final String text = "My text";

Translate.setClientId(<client id you type in the web site>);
Translate.setClientSecret(<secret 
you type in the web site  in Base 64 format>);

com.memetix.mst.language.Language from =
com.memetix.mst.language.Language.ENGLISH ;
com.memetix.mst.language.Language to =  com.memetix.mst.language.Language.RUSSIAN;
   
final String translatedText = Translate.execute(text, from, to);

 
Let me know if you need more details
Reply all
Reply to author
Forward
Message has been deleted
0 new messages