Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
        request.ContentLength = bytes.Length;
        outputstream = request.GetRequestStream();
        outputstream.Write(bytes, 0, bytes.Length);
    { }
    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);

public void GetuserProfile(string accesstoken)
    string url = ""+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();
    JavaScriptSerializer js = new JavaScriptSerializer();
    Userclass userinfo = js.Deserialize<Userclass>(responseFromServer);

What I have tried:

Tried to get token from google to use google's api functions
Richard MacCutchan 27-Oct-20 5:26am    
You need to go to contact Google for help.
Gerry Schmitz 27-Oct-20 12:18pm    
Tokens are dynamic and temporary; they're not currency. And you appear to be hard-coding a "key"; which doesn't make sense either. I think you're trying to hack someone's site because nothing you're doing is related to any actual authorization.
muharrem altun 29-Oct-20 6:33am    
İ am not hacker. Our company has more thean 1500 firms that sell our furnitures. These firms are located in google and we want to add, delete, update these firms using google api s. We try ourselves about it in google playground. In the playground firstly, the code can be get created when the url is given. After that the token can be get by using this code. If you have the google my bussiness ccount, you can try and see this. So we can not get the code, and the token

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900