Use WeiboAuthListener to obtain the code
Use the following code to obtain the token .. The sdks for semi-finished products are really urgent.
[Java]View plaincopy
[Java]View plaincopy
- String code = values. getString ("code ");
- If (code! = Null ){
- MText. setText ("Get authentication code: \ r \ n Code:" + code );
- Toast. makeText (MainActivity. this, "authentication code successful", Toast. LENGTH_SHORT). show ();
- }
- Try {
- URL url = new URL ("https://api.weibo.com/oauth2/access_token ");
- URLConnection connection = url. openConnection ();
- Connection. setDoOutput (true );
- OutputStreamWriter out = new OutputStreamWriter (connection
- . GetOutputStream (), "UTF-8 ");
- Out. write ("client_id = id & client_secret = secret & grant_type = authorization_code" +
- "& Code =" + code + "& redirect_uri = uri ");
- Out. flush ();
- Out. close ();
- String sCurrentLine;
- String sTotalString;
- SCurrentLine = "";
- STotalString = "";
- InputStream l_urlStream;
- Rochelle urlstream = connection. getInputStream ();
- BufferedReader l_reader = new BufferedReader (new InputStreamReader (
- Rochelle urlstream ));
- While (sCurrentLine = l_reader.readLine ())! = Null ){
- STotalString + = sCurrentLine;
- }
- JSONObject o = new JSONObject (sTotalString );
- System. out. println (o. getString ("access_token "));
- } Catch (Exception e ){
- // TODO Auto-generated catch block
- E. printStackTrace ();
- }