private void composeNewPost() { StatusesAPI api = new StatusesAPI(mAccessToken); mContent = mEdit.getText().toString(); if (TextUtils.isEmpty(mContent)) return; if (!TextUtils.isEmpty(mPicPath)) { Util.showToast(this, R.string.sending); api.upload(this.mContent, this.mPicPath, mLatitude, mLongitude, this); } else { // Just update a text weibo! api.update(mContent, mLatitude, mLongitude, this); } }
private void shareXinLang() { pDialog = ProgressDialog.show(context, "发布中", "请稍等...", true); StatusesAPI api = new StatusesAPI(accessToken); if (textString.length() >= 140) { Toasts.toast(context, "字数不能大于140字符"); return; } api.upload( textString, imagePath, "190.0", "190.0", new RequestListener() { @Override public void onIOException(IOException arg0) { message = new Message(); message.what = IOEXCEPTION; handler.sendMessage(message); Log.i("hck", arg0.toString()); } @Override public void onError(WeiboException arg0) { message = new Message(); message.what = ERROR; handler.sendMessage(message); Log.i("hck", arg0.toString()); } @Override public void onComplete(String arg0) { message = new Message(); message.what = SUCCESS; handler.sendMessage(message); } }); }
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; }