Answered by:
Microsoft Translator Access token

Question
-
hi,
I just found out about Microsoft translation and got all details from http://msdn.microsoft.com/en-us/library/hh454950.aspx
but when I run that code with my information on it I get The remote server returned an error: (400) Bad Request. Exception can any one help me out please
Thnaks
Friday, October 28, 2011 5:26 PM
Answers
-
Hi Dave,
the sample is fixed now. Sorry for taking a while. The client secret needs a UrlEncode().
Let us know if you run into something else.
Chris Wendt
Microsoft Translator- Marked as answer by Chris WendtMicrosoft employee Wednesday, November 30, 2011 2:22 AM
- Edited by Chris WendtMicrosoft employee Wednesday, November 30, 2011 2:23 AM slight edit.
Wednesday, November 30, 2011 2:22 AM -
The access token in valid for 10 minutes. The next access token you request will be different.
Chris Wendt
Microsoft Translator- Marked as answer by Bhanuj Friday, December 16, 2011 3:25 PM
Thursday, December 15, 2011 10:13 PM
All replies
-
I am keep getting this error. I dont know what I am doing wrong
bj2785Friday, October 28, 2011 6:50 PM -
Hi Bhanuj,
Just to make sure: you've registered here https://datamarket.azure.com/developer/applications/ and got your client_id and client_secret, right? Someone from our team will get back to you. Thanks for your patience. Takako --Microsoft Translator Team--
Saturday, October 29, 2011 12:09 AM -
Yes I am registered to https://datamarket.azure.com/developer/applications/ and I do have client_id and client_secret, right. I dont know something just doesn't make sense
Thanks
bj2785Monday, October 31, 2011 1:07 PM -
I've getting the same thing …
I've created AppId
Trying to use it as followed http://msdn.microsoft.com/en-us/library/ff512421.aspx
But I've got the following error: The remote server returned an error: (400) Bad Request.
It happens over this line response = httpWebRequest.GetResponse();
thanks
Monday, October 31, 2011 4:13 PM -
Hi.have you got a solution??? i am facing the same problem? thanksTuesday, November 1, 2011 6:47 PM
-
Is any one have solution for this?
bj2785Wednesday, November 2, 2011 2:20 PM -
I am getting this error when I try to get App ID
bj2785Wednesday, November 2, 2011 2:22 PM -
The sample was incorrect and will be updated soon.
The clientSecret parameter has to be UrlEncoded.
Thanks,
Max
Friday, November 18, 2011 10:25 PM -
Thanks, yes I found that this was the problem.
string request = string.Format(@"grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", clientId, HttpUtility.UrlEncode(clientSecret));
The sample is still not fixed though.
regards
DaveFriday, November 25, 2011 9:01 AM -
Hi Dave,
the sample is fixed now. Sorry for taking a while. The client secret needs a UrlEncode().
Let us know if you run into something else.
Chris Wendt
Microsoft Translator- Marked as answer by Chris WendtMicrosoft employee Wednesday, November 30, 2011 2:22 AM
- Edited by Chris WendtMicrosoft employee Wednesday, November 30, 2011 2:23 AM slight edit.
Wednesday, November 30, 2011 2:22 AM -
Hey Chris,
Do access token stays same all the time or each request it changes?
Thanks
bj2785Thursday, December 15, 2011 8:52 PM -
The access token in valid for 10 minutes. The next access token you request will be different.
Chris Wendt
Microsoft Translator- Marked as answer by Bhanuj Friday, December 16, 2011 3:25 PM
Thursday, December 15, 2011 10:13 PM -
So which exception i'll get if Access token is expired on SOAP Call?
bj2785Friday, December 16, 2011 3:23 PM -
So which exception i'll get if Access token is expired on SOAP Call?
bj2785If anyone's using the Client Profile for .NET instead of the full profile then you won't access to the HttpUtility.UrlEncode you will need to use Uri.EscapeDataString instead. DO NOT use Uri.EscapeUriString as it will NOT work.
After much trial and error this is what works for me:
string.Format(@"grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", Uri.EscapeDataString(Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(clientId))), Uri.EscapeDataString(Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(clientSecret))))
- Proposed as answer by jk sdkfj Friday, March 16, 2012 10:32 PM
Friday, March 16, 2012 10:31 PM