public static void authorize(Context context) { if (accessToken != null) return; if (!Util.isEmpty(Login.sinaWeiboToken) && !Util.isEmpty(Login.sinaExpiresIN)) { access_token = Login.sinaWeiboToken; expires_in = Login.sinaExpiresIN; accessToken = new Oauth2AccessToken(access_token, expires_in); if (!accessToken.isSessionValid()) { accessToken = null; } } WeiboParameters parameters = new WeiboParameters(); parameters.add("forcelogin", "true"); com.weibo.sdk.android.util.Utility.isWifi(context); weibo.startDialog( context, parameters, new WeiboAuthListener() { // weibo.authorize(context, new WeiboAuthListener() { @Override public void onComplete(Bundle bundle) { access_token = bundle.getString("access_token"); expires_in = bundle.getString("expires_in"); accessToken = new Oauth2AccessToken(access_token, expires_in); try { SendToken(); } catch (IOException e) { e.printStackTrace(); } } @Override public void onWeiboException(WeiboException e) { clearToken(); } @Override public void onError(WeiboDialogError weiboDialogError) { clearToken(); } @Override public void onCancel() { clearToken(); } }); }
public static String WeiboStatusUpload( Context context, final String content, final String pic, final RequestListener requestListener) { weiboUpLoadResult = "success"; if (accessToken == null) { WeiboParameters parameters = new WeiboParameters(); parameters.add("forcelogin", "true"); com.weibo.sdk.android.util.Utility.isWifi(context); weibo.startDialog( context, parameters, new WeiboAuthListener() { // weibo.authorize(context, new WeiboAuthListener() { @Override public void onComplete(Bundle bundle) { access_token = bundle.getString("access_token"); expires_in = bundle.getString("expires_in"); accessToken = new Oauth2AccessToken(access_token, expires_in); try { SendToken(); } catch (IOException e) { e.printStackTrace(); } StatusesAPI statusesAPI = new StatusesAPI(accessToken); if (requestListener != null) { statusesAPI.upload(content, pic, null, null, requestListener); } else { statusesAPI.upload( content, pic, null, null, new RequestListener() { @Override public void onComplete(String s) { weiboUpLoadResult = s; weiboUpLoadResult = "success"; // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show(); } @Override public void onIOException(IOException e) { weiboUpLoadResult = e.getMessage(); weiboUpLoadResult = "fail"; e.printStackTrace(); // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(), // Toast.LENGTH_SHORT).show(); } @Override public void onError(WeiboException e) { weiboUpLoadResult = e.getMessage(); weiboUpLoadResult = "fail"; e.printStackTrace(); // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(), // Toast.LENGTH_SHORT).show(); } }); } } @Override public void onWeiboException(WeiboException e) { weiboUpLoadResult = e.getMessage(); weiboUpLoadResult = "fail"; e.printStackTrace(); clearToken(); } @Override public void onError(WeiboDialogError weiboDialogError) { weiboUpLoadResult = weiboDialogError.getMessage(); weiboUpLoadResult = "fail"; weiboDialogError.printStackTrace(); clearToken(); } @Override public void onCancel() { clearToken(); } }); } else { StatusesAPI statusesAPI = new StatusesAPI(accessToken); if (requestListener != null) { statusesAPI.upload(content, pic, null, null, requestListener); } else { statusesAPI.upload( content, pic, null, null, new RequestListener() { @Override public void onComplete(String s) { weiboUpLoadResult = s; weiboUpLoadResult = "success"; // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show(); } @Override public void onIOException(IOException e) { weiboUpLoadResult = e.getMessage(); weiboUpLoadResult = "fail"; e.printStackTrace(); // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(), // Toast.LENGTH_SHORT).show(); } @Override public void onError(WeiboException e) { weiboUpLoadResult = e.getMessage(); weiboUpLoadResult = "fail"; e.printStackTrace(); // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(), // Toast.LENGTH_SHORT).show(); } }); } } return weiboUpLoadResult; }