我想要在软件里面加个按钮点击一下可以发微博,但是从微博API的DEMO拷了代码过来不知道为什么点了之后可以出来登陆界面,但是登陆后不会转到发微博的界面,登陆后再点按钮就没有反应了LOGCAT也没半点信息出来ORZ 代码如下 public class ContrastActivity extends Activity implements OnClickListener, IWeiboHandler.Response { private static final String TAG = "ContrastActivity"; public static final String KEY_SHARE_TYPE = "key_share_type"; public static final int SHARE_CLIENT = 1; public static final int SHARE_ALL_IN_ONE = 2; // private Button mSharedBtn; private LinearLayout mSharedBtn; private IWeiboShareAPI mWeiboShareAPI = null; private int mShareType = SHARE_CLIENT; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.con_activity); initViews(); mShareType = getIntent().getIntExtra(KEY_SHARE_TYPE, SHARE_CLIENT); mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, Constants.APP_KEY); mWeiboShareAPI.registerApp(); if (savedInstanceState != null) { mWeiboShareAPI.handleWeiboResponse(getIntent(), this); } } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); mWeiboShareAPI.handleWeiboResponse(intent, this); } @Override public void onResponse(BaseResponse baseResp) { switch (baseResp.errCode) { case WBConstants.ErrorCode.ERR_OK: Toast.makeText(this, R.string.weibosdk_demo_toast_share_success, Toast.LENGTH_LONG).show(); break; case WBConstants.ErrorCode.ERR_CANCEL: Toast.makeText(this, R.string.weibosdk_demo_toast_share_canceled, Toast.LENGTH_LONG).show(); break; case WBConstants.ErrorCode.ERR_FAIL: Toast.makeText( this, getString(R.string.weibosdk_demo_toast_share_failed) + "Error Message: " + baseResp.errMsg, Toast.LENGTH_LONG).show(); break; } } private void initViews() { mSharedBtn = (LinearLayout) findViewById(R.id.share_weibo); mSharedBtn.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.share_weibo: sendMessage(); break; default: break; } } private void sendMessage() { if (mShareType == SHARE_CLIENT) { if (mWeiboShareAPI.isWeiboAppSupportAPI()) { int supportApi = mWeiboShareAPI.getWeiboAppSupportAPI(); if (supportApi >= 10351 /* ApiUtils.BUILD_INT_VER_2_2 */) { Log.v("tag", "mil1"); sendMultiMessage(); } else { Log.v("tag", "sing"); sendSingleMessage(); } } else { Toast.makeText(this, R.string.weibosdk_demo_not_support_api_hint, Toast.LENGTH_SHORT).show(); } } else if (mShareType == SHARE_ALL_IN_ONE) { Log.v("tag", "mil2"); sendMultiMessage(); } } private void sendSingleMessage() { // 1. 初始化微博的分享消息 // 用户可以分享文本、图片、网页、音乐、视频中的一种 WeiboMessage weiboMessage = new WeiboMessage(); weiboMessage.mediaObject = getTextObj(); // 2. 初始化从第三方到微博的消息请求 SendMessageToWeiboRequest request = new SendMessageToWeiboRequest(); // 用transaction唯一标识一个请求 request.transaction = String.valueOf(System.currentTimeMillis()); request.message = weiboMessage; // 3. 发送请求消息到微博,唤起微博分享界面 mWeiboShareAPI.sendRequest(ContrastActivity.this, request); } private void sendMultiMessage() { WeiboMultiMessage weiboMessage = new WeiboMultiMessage(); weiboMessage.textObject = getTextObj(); SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest(); request.transaction = String.valueOf(System.currentTimeMillis()); request.multiMessage = weiboMessage; if (mShareType == SHARE_CLIENT) { Log.v("tag", "唤起1"); mWeiboShareAPI.sendRequest(ContrastActivity.this, request); } else if (mShareType == SHARE_ALL_IN_ONE) { AuthInfo authInfo = new AuthInfo(this, Constants.APP_KEY, Constants.REDIRECT_URL, Constants.SCOPE); Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(getApplicationContext()); String token = ""; if (accessToken != null) { token = accessToken.getToken(); } Log.v("tag", "唤起2"); mWeiboShareAPI.sendRequest(this, request, authInfo, token, new WeiboAuthListener() { @Override public void onWeiboException( WeiboException arg0 ) { } @Override public void onComplete( Bundle bundle ) { // TODO Auto-generated method stub Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle); AccessTokenKeeper.writeAccessToken(getApplicationContext(), newToken); Toast.makeText(getApplicationContext(), "onAuthorizeComplete token = " + newToken.getToken(), 0).show(); } @Override public void onCancel() { } }); } } private String getSharedText() { int formatId = R.string.weibosdk_demo_share_text_template; String format = getString(formatId); String text = format; format = getString(R.string.weibosdk_demo_share_text_template); return text; } private TextObject getTextObj() { TextObject textObject = new TextObject(); textObject.text = getSharedText(); return textObject; } } DEMO的代码如下,因为我只要能发文字就可以了所以把其他的都删了,代码贴上去超帖子字数了弄个网盘… |
|
100分 |
都没人回答吗
|