android - Get PayPal Access token in Lollipop -
so trying make app users swipe credit card , bluetooth device handle it. using paypal sdk cant seem figure out how access token use request. here current code:
public string performpostcall(string requesturl, hashmap<string, string> postdataparams) { url url; string response = ""; try { url = new url(requesturl); httpurlconnection conn = (httpurlconnection) url.openconnection(); conn.setreadtimeout(15000); conn.setconnecttimeout(15000); conn.setrequestmethod("post"); conn.setdoinput(true); conn.setdooutput(true); conn.setrequestproperty("accept", "application/json"); outputstream os = conn.getoutputstream(); bufferedwriter writer = new bufferedwriter( new outputstreamwriter(os, "utf-8")); writer.write(getpostdatastring(postdataparams)); writer.flush(); writer.close(); os.close(); int responsecode=conn.getresponsecode(); if (responsecode == httpsurlconnection.http_ok) { string line; bufferedreader br=new bufferedreader(new inputstreamreader(conn.getinputstream())); while ((line=br.readline()) != null) { response+=line; } } else { response=""; } } catch (exception e) { e.printstacktrace(); } return response; } private string getpostdatastring(hashmap<string, string> params) throws unsupportedencodingexception { stringbuilder result = new stringbuilder(); boolean first = true; for(map.entry<string, string> entry : params.entryset()){ if (first) first = false; else result.append("&"); result.append(urlencoder.encode(entry.getkey(), "utf-8")); result.append("="); result.append(urlencoder.encode(entry.getvalue(), "utf-8")); } return result.tostring(); } public string getpaypaltoken() { hashmap<string, string> params = new hashmap<string, string>(); string client_id = "no"; string secret = "no"; params.put("username", base64.encodetostring((client_id + ":" + secret).getbytes(), base64.default)); params.put("grant_type", "client_credentials"); system.out.println("params: " + params); string output = performpostcall("https://api.sandbox.paypal.com/v1/oauth2/token", params); system.out.println("output: " + output); return output; }
i know unsafe put client_id
, secret
in android device place app going device. paypal returning nothing, , have no clue why. if give me pointers or maybe code nice. :)
Comments
Post a Comment