c# - How to get Authorization code in Bing Ads Api for long term authentication -


how authorization code long term authentication. using bing ads api v 9.0.

here code.

string urlstring = "https://login.live.com/oauth20_authorize.srf?client_id=" + clientid + "&scope=bingads.manage&response_type=code&redirect_uri=" + "https://login.live.com/oauth20_desktop.srf";             var realuri = new uri(urlstring,urikind.absolute);             var addy = realuri.absoluteuri.substring(0, realuri.absoluteuri.length - realuri.query.length);             var myclient = webrequest.create(addy) httpwebrequest;             myclient.method = webrequestmethods.http.post;             myclient.headers[httprequestheader.acceptlanguage]="en-us";             myclient.contenttype = "application/x-www-form-urlencoded";             using (var writer = new streamwriter(myclient.getrequeststream()))             {                 writer.write(realuri.query.substring(1));             }              var response = (httpwebresponse)myclient.getresponse();              (int = 0; < response.headers.count; i++)             {                 console.writeline(response.headers.getkey(i) + " -- " + response.headers.get(i).tostring());             }             var responseserializer = new datacontractjsonserializer(typeof(accesstokens));             accesstokens tokenresponse = null;             using (stream responsestream = response.getresponsestream())             {                 if (responsestream != null)                     tokenresponse = (accesstokens)responseserializer.readobject(responsestream);             } 

i following this documentation.

the below following code generates authorization code web.

private const string clientid = "xxxxxxxxxxxxxx";  private const string redirectionuri = "your redirection url"; // redirection url should defined during app registration. string urlstring = "https://login.live.com/oauth20_authorize.srf?client_id=" + clientid + "&scope=bingads.manage&response_type=code&redirect_uri=" + redirectionuri; response.redirect(urlstring); 

the response.redirect(urlstring) redirected page. authorization code on redirection page using

string authcode = request.querystring["code"]; 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -