Hello all,

        I registered the account of the Google translation, and the 
translation of the API key, but in the translation, but reported URL 403 
error, why so, how to solve?
        Google translation of URL for 
http://www.googleapis.com/language/translate/v2? 
Key=MyAppKey&source=en&target=it  

        My Code is:
         private const string TRANSLATE_API_FORMAT = 
"http://www.googleapis.com/language/translate/v2?key={0}&source={1}&target={2}";;

        private string BuildPostData(params string[] source)
        {
            const string QUERY_PARAM = "q";
            StringBuilder data = new StringBuilder();
            foreach (var item in source)
            {
                data.AppendFormat("{0}={1}&", QUERY_PARAM, 
 HttpUtility.UrlEncode(item));
            }
            if (data.Length > 0)
            {
                data.Remove(data.Length - 1, 1);
            }
            return data.ToString();
        }

        private GoogleTranslateResult PostDataToTranslate(params string[] 
source)
        {
            string data = BuildPostData(source);

            Encoding encoding = Encoding.UTF8;
            byte[] bytesToPost = encoding.GetBytes(data);

            HttpWebRequest request = 
(HttpWebRequest)WebRequest.Create(TranslateUrl);
            request.Headers.Add("X-HTTP-Method-Override", "GET");
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
             
            request.ContentLength = bytesToPost.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytesToPost, 0, bytesToPost.Length);
                requestStream.Close();
            }
            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(stream, 
encoding))
                    {
                        string jsonData = sr.ReadToEnd();
                        GoogleTranslateResult result = 
JsonConvert.DeserializeObject<GoogleTranslateResult>(jsonData);
                        result.SourceData = source;
                        return result;
                    }
                }
            }
        }



Thank you!
       

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/281f7d49-e6a2-43c1-9ba2-3d4acf26157c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to