com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest Java Examples

The following examples show how to use com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SharePresenter.java    From the-tech-frontier-app with MIT License 6 votes vote down vote up
/**
 * 分享文章到新浪微博
 * 
 * @param title
 * @param url
 */
public void share(Activity activity, String title, String url) {
    WeiboMultiMessage weiboMessage = new WeiboMultiMessage();// 初始化微博的分享消息
    TextObject textObject = new TextObject();
    textObject.text = "《" + title + "》" + "这篇文章不错, 文章地址 : " + url
            + "。本文来自: 开发技术前线, http://www.devtf.cn 。";
    weiboMessage.textObject = textObject;
    ImageObject imageObject = new ImageObject();
    imageObject.setImageObject(BitmapFactory.decodeResource(activity.getResources(),
            R.drawable.ic_launcher));
    weiboMessage.imageObject = imageObject;
    SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
    request.transaction = String.valueOf(System.currentTimeMillis());
    request.multiMessage = weiboMessage;
    mWeiboShareAPI.sendRequest(activity, request); // 发送请求消息到微博,唤起微博分享界面
}
 
Example #2
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
private void share2weibo() {
	setShareContent();
	// 1. 初始化微博的分享消息
       WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
       weiboMessage.mediaObject = getWebpageObj();
       weiboMessage.textObject = getTextObj();    //这里可以设置文本
       if(mJoke.getType() != Joke.TYPE_QUSHI) {
       	weiboMessage.imageObject = getImageObj();
       }
      // 2. 初始化从第三方到微博的消息请求
       SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
       // 用transaction唯一标识一个请求
       request.transaction = String.valueOf(System.currentTimeMillis());
       request.multiMessage = weiboMessage;
       
       AuthInfo authInfo = new AuthInfo(context, com.sina.weibo.Constants.APP_KEY, com.sina.weibo.Constants.REDIRECT_URL, com.sina.weibo.Constants.SCOPE);
       Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(context);
       String token = "";
       if (accessToken != null) {
           token = accessToken.getToken();
       }
       mWeiboShareAPI.sendRequest((Activity)context, request, authInfo, token, new WeiboAuthListener() {
           @Override
           public void onWeiboException( WeiboException arg0 ) {
           	Log.e(TAG, "share sina weibo error", arg0);
           	ToastUtils.showMessage(context, "分享失败");
           }
           @Override
           public void onComplete( Bundle bundle ) {
               Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
               AccessTokenKeeper.writeAccessToken(context, newToken);
               ImgToastUtils.showMessage(context, "分享成功", R.drawable.center_ok_tip);
           }
           @Override
           public void onCancel() {
           }
       });
}
 
Example #3
Source File: WeiboShareProxy.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
private static void shareTo(final Context context, final String appKey, final String redirectUrl, final String scop, final String title, final String desc,
                            final String imageUrl, final String shareUrl, final WeiboAuthListener listener) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeiboMultiMessage msg = new WeiboMultiMessage();
            TextObject text = new TextObject();
            text.text = desc;
            msg.textObject = text;
            WebpageObject web = new WebpageObject();
            web.description = desc;
            byte[] thumb = SocialUtils.getHtmlByteArray(imageUrl);
            if (null != thumb)
                web.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                web.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);
            web.actionUrl = shareUrl;
            web.identify = imageUrl;
            web.title = title;
            msg.mediaObject = web;

            SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
            request.transaction = String.valueOf(System.currentTimeMillis());
            request.multiMessage = msg;

            AuthInfo authInfo = new AuthInfo(context, appKey, redirectUrl, scop);
            Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(context);
            String token = "";
            if (accessToken != null) {
                token = accessToken.getToken();
            }
            getInstance(context, appKey).sendRequest((Activity) context, request, authInfo, token, listener);
        }
    }).start();

}
 
Example #4
Source File: WeiboShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
private void sendRequest(Activity activity, WeiboMultiMessage message) {
    SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
    request.transaction = String.valueOf(System.currentTimeMillis());
    request.multiMessage = message;
    mWeiboShareAPI.sendRequest(activity, request);
}
 
Example #5
Source File: WeiboShareInstance.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
private void sendRequest(Activity activity, WeiboMultiMessage message) {
    SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
    request.transaction = String.valueOf(System.currentTimeMillis());
    request.multiMessage = message;
    mWeiboShareAPI.sendRequest(activity, request);
}
 
Example #6
Source File: SinaWBHandler.java    From SocialSDKAndroid with Apache License 2.0 4 votes vote down vote up
@Override
    public void share(Activity activity, IShareMedia shareMedia, ShareListener shareListener) {
        this.mActivity = activity;
        this.mShareListener = shareListener;

        this.mSsoHandler = new SsoHandler(mActivity, mAuthInfo);

        WeiboMultiMessage weiboMessage = new WeiboMultiMessage();

        if(shareMedia instanceof ShareTextImageMedia) {       //文字图片分享
            ShareTextImageMedia shareTextImageMedia = (ShareTextImageMedia) shareMedia;

            if(shareTextImageMedia.getText().length() > 0) {
                TextObject textObject = new TextObject();
                textObject.text = shareTextImageMedia.getText();
                weiboMessage.textObject = textObject;
            }

            if(shareTextImageMedia.getImage() != null) {
                ImageObject imageObject = new ImageObject();
                imageObject.setImageObject(shareTextImageMedia.getImage());
                weiboMessage.imageObject = imageObject;
            }
        } else {
            if(this.mShareListener != null) {
                this.mShareListener.onError(this.mConfig.getName(), "weibo is not support this shareMedia");
            }
            return ;
        }

        SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
        request.transaction = String.valueOf(System.currentTimeMillis());
        request.multiMessage = weiboMessage;

        Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(mContext.getApplicationContext());
        String token = "";
        if (accessToken != null) {
            token = accessToken.getToken();
        }
        mWeiboShareAPI.sendRequest(mActivity, request, mAuthInfo, 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(mContext.getApplicationContext(), newToken);
            }

            @Override
            public void onCancel() {
            }
        });

//        mWeiboShareAPI.sendRequest(mActivity, request);
    }