I have some code that should get the code to get token from google my business to use google my business api function. To get token, the code is needed. How can i get the code to get token? Can anyone help me please? Here is the part of my code that i use: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //if (Request.QueryString["code"] != null) if (Request.QueryString["code"]==null) { //Request.QueryString["code"] = Request.QueryString["code"]; GetToken("4/2gGIZ51sCTJ2XNG4xbf-HG_BbNF3nu-PIPaOGJNOT4m2j9mVQtRKBRy7kCIeEj7iAVEXW1MJGoGy8YE3fkxoMsQ"); } } } public void GetToken(string code) {
string poststring="grant_type=authorization_code&code="+code+ "&client_id="+clientid+ "&client_secret="+clientsecret+ "&redirect_uri="+redirection_url+""; var request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; UTF8Encoding utfenc = new UTF8Encoding(); byte[] bytes = utfenc.GetBytes(poststring); Stream outputstream = null; try { request.ContentLength = bytes.Length; outputstream = request.GetRequestStream(); outputstream.Write(bytes, 0, bytes.Length); } catch { } var response = (HttpWebResponse)request.GetResponse(); var streamReader = new StreamReader(response.GetResponseStream()); string responseFromServer = streamReader.ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); Tokenclass obj = js.Deserialize<Tokenclass>(responseFromServer); GetuserProfile(obj.access_token); } public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token="+accesstoken+""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize<Userclass>(responseFromServer); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)