Beispiel #1
0
        private AdmAccessToken HttpPost(string DatamarketAccessUri, string requestDetails)
        {
            //Prepare OAuth request
            WebRequest webRequest = WebRequest.Create(DatamarketAccessUri);

            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.Method      = "POST";
            byte[] bytes = Encoding.ASCII.GetBytes(requestDetails);
            webRequest.ContentLength = bytes.Length;
            using (Stream outputStream = webRequest.GetRequestStream())
            {
                outputStream.Write(bytes, 0, bytes.Length);
            }
            using (WebResponse webResponse = webRequest.GetResponse())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AdmAccessToken));
                //Get deserialized object from JSON stream
                AdmAccessToken token = (AdmAccessToken)serializer.ReadObject(webResponse.GetResponseStream());
                return(token);
            }
        }
        public string GetBingAPITranslationToken()
        {
            string token = "";
            AdmAccessToken admToken;


            AdmAuthentication admAuth = new AdmAuthentication("portugal_rental_cottages", "okyIIda04oNosmgTuhDaJeGQCkkzniuXTieU+2/6bjU=");
            //AdmAuthentication admAuth = new AdmAuthentication("portugal_rental_cottages2", "OJ95iUpcz46bfiCDr3HuPZ3cGpSVBtXOwIzIfD50sdA=");

            try
            {
                admToken = admAuth.GetAccessToken();

                token = "Bearer " + admToken.access_token;

            }

            catch (Exception ex)
            {
                //ex.InnerException.ToString();

                //the translator won't work but hey, f**k it. 
                admToken = new AdmAccessToken();
                return token;
            }


            return token;
        }