普通分享到微博

1.配置清单

2.添加依赖

implementation'com.sina.weibo.sdk:core:9.12.0:openDefaultRelease@aar'

implementation"com.umeng.umsdk:common:9.1.0"

implementation"com.umeng.umsdk:asms:1.1.3" // asms包依赖(必选)

implementation"com.umeng.umsdk:crash:0.0.4" // native crash包依赖(必选

buildscript{

    repositories{

        google()

        jcenter()

        maven{ url'https://dl.bintray.com/thelasterstar/maven/'}

        maven{ url'https://dl.bintray.com/umsdk/release' }

}

3.在MainActivity做代码操作

//先初始化

private static final String APP_KY ="238827885";

private static final String REDIRECT_URL ="http://www.sina.com";

private static final String SCOPE =

"email,direct_messages_read,direct_messages_write,"

                +"friendships_groups_read,friendships_groups_write,statuses_to_me_read,"

                +"follow_app_official_microblog," +"invitation_write";

private IWBAPI mWBAPI;

oncreate中添加  代码初始化方法      initSdk();

private void initSdk() {

AuthInfo authInfo =new AuthInfo(this,APP_KY,REDIRECT_URL,SCOPE);

mWBAPI =WBAPIFactory.createWBAPI(this);

mWBAPI.registerApp(this,authInfo);

}

//判断点击之后的分享操作

private void startAuth() {

//auth

    mWBAPI.authorize(new WbAuthListener() {

@Override

        public void onComplete(Oauth2AccessToken token) {

Toast.makeText(MainActivity.this,"微博授权成功",Toast.LENGTH_SHORT).show();

}

@Override

        public void onError(UiError error) {

Toast.makeText(MainActivity.this,"微博授权出错",Toast.LENGTH_SHORT).show();

}

@Override

        public void onCancel() {

Toast.makeText(MainActivity.this,"微博授权出错",Toast.LENGTH_SHORT).show();

}

});

}

//重写方法

@Override

protected void onActivityResult(int requestCode,int resultCode,@Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (mWBAPI !=null) {

mWBAPI.authorizeCallback(requestCode, resultCode, data);

}

}

//实线     WbShareCallback接口三个方法


//点击按钮执行分享方法

private void doWeiboShare() {

WeiboMultiMessage message =new WeiboMultiMessage();

TextObject textObject =new TextObject();

String text ="测试";

textObject.text =text;

message.textObject =textObject;

mWBAPI.shareMessage(message,true);

}

你可能感兴趣的:(普通分享到微博)