Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getToken() not working on Android #36

Closed
rmtheis opened this issue May 26, 2012 · 5 comments
Closed

getToken() not working on Android #36

rmtheis opened this issue May 26, 2012 · 5 comments

Comments

@rmtheis
Copy link
Contributor

rmtheis commented May 26, 2012

There seems to be a problem with the POST in getToken() not returning a result when running on Android.

I tested it on Android 4.0.2. When I replaced the method with a new one using Apache Commons' HttpClient instead of HttpURLConnection, the method worked. HttpURLConnection is the recommended HTTP client on Android 2.3.x, though. [1]

Sorry for the lack of detail on this--I plan to take a closer look when I have a chance.

[1] http://android-developers.blogspot.com/2011/09/androids-http-clients.html

@boatmeme
Copy link
Owner

Hi Robert -

I'm wondering if you have had success with this lately?

I ran a Translate.execute() on Android 4.0.3 and v0.6.1 of the microsoft-translator-java-api, and was unable to reproduce the problem.

Please advise, and if it is no longer a problem, I will close this issue.

Thanks!
-jg

@rmtheis
Copy link
Contributor Author

rmtheis commented Jun 27, 2012

Jonathan-

Did you test using a Client Id and Client Secret, or an App ID?

I'm still seeing an error with Android 4.0.3 and microsoft-translator-java-api v0.6.1. The stack trace is below. The only thing I'm doing that's unusual is running in an AsyncTask to avoid getting a NetworkOnMainThreadException. [1]

While I don't think this is really a bug in this project, please consider keeping this issue open in case we can find a workaround.
Robert

06-27 01:03:21.450: W/System.err(15812): java.lang.Exception: [microsoft-translator-api] Error retrieving translation : https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
06-27 01:03:21.450: W/System.err(15812):    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
06-27 01:03:21.450: W/System.err(15812):    at com.memetix.mst.translate.Translate.execute(Translate.java:61)
06-27 01:03:21.450: W/System.err(15812):    at com.robtheis.bingtest.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:30)
06-27 01:03:21.450: W/System.err(15812):    at com.robtheis.bingtest.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:1)
06-27 01:03:21.450: W/System.err(15812):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-27 01:03:21.450: W/System.err(15812):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-27 01:03:21.450: W/System.err(15812):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-27 01:03:21.450: W/System.err(15812):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
06-27 01:03:21.450: W/System.err(15812):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-27 01:03:21.450: W/System.err(15812):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-27 01:03:21.450: W/System.err(15812):    at java.lang.Thread.run(Thread.java:856)
06-27 01:03:21.450: W/System.err(15812): Caused by: java.io.FileNotFoundException: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
06-27 01:03:21.450: W/System.err(15812):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
06-27 01:03:21.450: W/System.err(15812):    at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
06-27 01:03:21.450: W/System.err(15812):    at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:139)
06-27 01:03:21.450: W/System.err(15812):    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
06-27 01:03:21.450: W/System.err(15812):    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
06-27 01:03:21.450: W/System.err(15812):    ... 10 more

[1] http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

@boatmeme
Copy link
Owner

I was setting only clientId and clientSecret, so I know that it was making the call to getToken() successfully. Also, I was invoking Translate.execute() from an AsyncTask.

One thing I did not do was run the code on an actual Android device. I tested it on a 4.0.3 AVD image only, which may be why we're seeing different behavior. Unfortunately, I'm not sure I'll be able to get my hands on a device running 4.0.3 any time soon.

I agree, we should keep this issue open until it has been solved.

@bachnv88
Copy link

I also have met this error.
After re-checking my mistake is:
I had used Primary Account Key instead of CLIENT_SECRET
The CLIENT_SECRET you can get when you register for a clientId and clientSecret with Microsoft's Windows Azure Marketplace

Hope that can help you!

@githubwebber
Copy link

I have a problem, using microsoft-translator-java-api-0.6.1-jar-with-dependencies.jar api for android 4.0,i can't get
for ( Language lang : Language.values()) { lang.getname(Language.French)}; i cann't get language name. log displays an error [microsoft-translator-api] Error retrieving translation. Why I used android 2.3.3 This error does not occur, but the android 4.0 error,please tell me how to fix this !! thanks .

@rmtheis rmtheis closed this as completed Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants