i trying access drive api javafx desktop app. after received initial authentication (aka code
), want token able work api. config set native application in dev console.
when attempt fetch token various http-errors (400, 401, 404, 405, 406, 411). guess wrong encoding and/or way send request server. here code:
public void sendoauth2tokenrequest(string initialoauth2) { final string charset = "utf-8"; try { string url = "https://www.googleapis.com/oauth2/v3/token"; httpsurlconnection con = (httpsurlconnection) new url(url).openconnection(); con.setdooutput(true); con.setrequestmethod("post"); con.setrequestproperty("accept-charset", charset); con.setrequestproperty("content-type", "application/x-www-form-urlencoded"); outputstream output = con.getoutputstream(); output.write(getencodedurlparms().getbytes(charset)); output.close(); bufferedreader responsereader = new bufferedreader(new inputstreamreader(con.getinputstream(), charset)); string inputline; stringbuilder response = new stringbuilder(); while ((inputline = responsereader.readline()) != null) { response.append(inputline); } log.i(tag, "oauth2request " + inputline); responsereader.close(); } catch (ioexception e) { e.printstacktrace(); log.e(tag, "oauth2request error: " + e.getmessage()); } } private string getencodedurlparms() throws unsupportedencodingexception { return "code=" + urlencoder.encode(getinitialcode(), "utf-8") + "&client_id=" + urlencoder.encode(drivehelper.client_id, "utf-8") + "&client_secret=" + urlencoder.encode(drivehelper.client_secret, "utf-8") + "&redirect_uri=" + urlencoder.encode("urn:ietf:wg:oauth:2.0:oob", "utf-8") + "&grant_type=" + urlencoder.encode("authorization_code", "utf-8"); }
please let me know mean here:
the client secret obtained developers console (optional clients registered android, ios or chrome applications).
is client_secret
needed (mandatory) in native apps?
Comments
Post a Comment