zoukankan      html  css  js  c++  java
  • android shareSDK 微博分享案例

    android shareSDK 微博分享案例

    ShareSDK
    APP_KEY 219b1121fc68


    腾讯微博
    key 801517904
    secret bfba83ae253c8f38dabe22c5fa4093bd




    新浪微博
    key 3815341537
    secret f19fb8f89acc090716de7e3bde2e5f9e
    回调页:https://api.weibo.com/oauth2/default.html
    包名+keySotre签名:91f05bce6758f1a1e870a4f3fa5f871b


    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    准备阶段:


    使用ShareSDK步骤
    1. ShareSDK官网,创建应用 获取Key
    2. ShareSDK官网。下载SDK
    3. 使ShareSDK的DEMO正常执行
    (类库:ShareSDK for Android
      demo:ShareSDK for Android Sample)
    4.创建新的项目
    5.去各平台注冊key
    新浪微博:
     a.证书签名须要个人证书导出项目时获取到
    MD5 : 91:F0:5B:CE:67:58:F1:A1:E8:70:A4:F3:FA:5F:87:1B
    证书格式为小写字母并不含:
    91f05bce6758f1a1e870a4f3fa5f871b
     b.授权回调页:https://api.weibo.com/oauth2/default.html

    6.sample里全部的图片以及values拷入当前新的项目: 

    此时须要改动 main_activity.xml  and  menu.xml 中跟 @String/ 有关的信息。

    7.sample里asset里Sharesdk.xml拷入当前新的项目。而且改动指定内容
    RedirectUrl:假设指定授权回调页。就填写回调页。如没有,就填写应用网址
    8.须要把sample里mainifest中的权限拷入当前新的项目
    9.sample里mainifest中的ShareSDKUIShell,activity注冊到当前新的项目中,代码例如以下:
    <activity
    android:name="cn.sharesdk.framework.ShareSDKUIShell"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"android:configChanges="keyboardHidden|orientation|screenSize"android:windowSoftInputMode="stateHidden|adjustResize" >
     </activity>
     10.拷入须要用到的jar包
     必拷:mframework.jar
     必拷:ShareSDK-Core-2.3.8jar

     分享指定平台:
     ShareSDK-XXX.jar

     11.将onkeyshare包复制到当前项目中


    分享步骤:

     ***************************
     1.初始化ShareSDK
     ShareSDK.init(this);
     2.设置指定平台
     Platform p=ShareSDK.getPlatform(XXX.NAME);
     3.设置平台监听器
     p.setPlatform
     AcitonListener{
      1.error
      2.complete
      3.cancel
     }
     4.进行授权
     p.rauthorize();
     5.重写平台监听器中的complete
     获取某平台參数对象
     Platform.ShareParams ps=
     new XXX.ShareParams();
     加入要分享的数据
     ps.setText/setImageUrl/set..
     分享

     p.share(ps);



    分享案例代码:

    package com.example.lovesharesdkdemo;
    
    import java.util.HashMap;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.TextView;
    import cn.sharesdk.framework.Platform;
    import cn.sharesdk.framework.PlatformActionListener;
    import cn.sharesdk.framework.ShareSDK;
    import cn.sharesdk.tencent.weibo.TencentWeibo;
    
    public class MainActivity extends Activity {
    
    	private Platform platform;
    	
    	private TextView textView;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		//1 初始化SDK
    		ShareSDK.initSDK(getApplicationContext());
    		//2.设置指定平台
    		platform = ShareSDK.getPlatform(TencentWeibo.NAME);
    		//3 获取组件  注冊事件
    		textView = (TextView) this.findViewById(R.id.buttton);
    		textView.setOnClickListener(new OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				//TOFO 分享SDK
    				getShareSDK();
    			}
    
    			private void getShareSDK() {
    				//3  给平台加入 listener
    				platform.setPlatformActionListener(new PlatformActionListener() {
    					
    					@Override
    					public void onError(Platform arg0, int arg1, Throwable arg2) {
    						// TODO error useful
    						Log.i("error", "---error="+arg2.getLocalizedMessage());
    					}
    					
    					@Override
    					public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) {
    						// TODO finished useful
    						
    						//设置分享的參数:
    						TencentWeibo.ShareParams shareParams = new TencentWeibo.ShareParams();
    						
    						shareParams.setText("美女的世界");
    						shareParams.setImageUrl("http://t12.baidu.com/it/u=750616964,1500186643&fm=59");
    						
    						// 分享
    						platform.share(shareParams);				
    					}
    					
    					@Override
    					public void onCancel(Platform arg0, int arg1) {
    						// TODO cancel
    						
    					}
    				});
    				
    				//4 授权平台!  异步任务:
    				platform.authorize();
    			}
    		});
    		
    	}
    
    	@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;
    	}
    
    }
    


    androidmainfes.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.lovesharesdkdemo"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="19" />
        
    <!--     权限设置 -->
        <uses-permission android:name="android.permission.GET_TASKS" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
        <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
        
        
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.lovesharesdkdemo.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            
           <!--  SdkShare frameWork -->
            <activity
                android:name="cn.sharesdk.framework.ShareSDKUIShell"
                android:theme="@android:style/Theme.Translucent.NoTitleBar"
                android:configChanges="keyboardHidden|orientation|screenSize"
                android:windowSoftInputMode="stateHidden|adjustResize" >
             </activity>
            
            
        </application>
    
    </manifest>
    


    ShareSDK.xml

    <?xml version="1.0" encoding="utf-8"?>
    <DevInfor>
        <!--
        	说明:
        	
        	1、表格中的第一项
        		<ShareSDK 
            		AppKey="api20" />
        	是必须的,当中的AppKey是您在ShareSDK上注冊的开发人员帐号的AppKey
        	
        	2、全部集成到您项目的平台都应该为其在表格中填写相相应的开发人员信息。以新浪微博为例:
        	    <SinaWeibo
                    Id="1"
                    SortId="1"
                    AppKey="568898243"
                    AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
                    RedirectUrl="http://www.sharesdk.cn"
                    Enable="true" />
        	当中的SortId是此平台在分享列表中的位置,由开发人员自行定义,能够是不论什么整型数字,数值越大
        	越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注冊开发人员信息和应用后得到的信息
        	Id是一个保留的识别符,整型,ShareSDK不使用此字段。供您在自己的项目中当作平台的识别符。
        	Enable字段表示此平台是否有效。布尔值,默觉得true。假设Enable为false。即便平台的jar包
        	已经加入到应用中。平台实例依旧不可获取。
        	
        	各个平台注冊应用信息的地址例如以下:
    			新浪微博                 http://open.weibo.com
    			腾讯微博                 http://dev.t.qq.com
    			QQ空间                      http://connect.qq.com/intro/login/
    			微信好友                 http://open.weixin.qq.com
    			Facebook      https://developers.facebook.com
    			Twitter       https://dev.twitter.com
    			人人网                      http://dev.renren.com
    			开心网                      http://open.kaixin001.com
    			搜狐微博                 http://open.t.sohu.com
    			网易微博                 http://open.t.163.com
    			豆瓣                           http://developers.douban.com
    			
    			有道云笔记            http://note.youdao.com/open/developguide.html#app
    			印象笔记                 https://dev.evernote.com/
    			Linkedin      https://www.linkedin.com/secure/developer?newapp=
    			FourSquare    https://developer.foursquare.com/
    			搜狐随身看            https://open.sohu.com/
    			Flickr        http://www.flickr.com/services/
    			Pinterest     http://developers.pinterest.com/
    			Tumblr        http://www.tumblr.com/developers
    			Dropbox       https://www.dropbox.com/developers
    			Instagram     http://instagram.com/developer#
    			VKontakte     http://vk.com/dev
    			易信好友          	http://open.yixin.im/
    			明道	    http://open.mingdao.com/
    			Line	http://media.line.me/zh-hant/
        -->
        
        <!-- 改动成你在sharesdk后台注冊的应用的appkey"-->
        <ShareSDK 
            AppKey = "3500df6f55df"/> 
        
        <!-- ShareByAppClient标识是否使用微博client分享,默认是false -->
        <SinaWeibo
            Id="1"
            SortId="1"
            AppKey="568898243"
            AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
            RedirectUrl="http://www.sharesdk.cn"
            ShareByAppClient="false"
            Enable="true" />
    
      <!--   腾讯微博 -->
        <TencentWeibo
            Id="2" 
            SortId="2"
            AppKey="801545336"
            AppSecret="b3def3a6ff684bee7de4e49d7884c0b3"
            RedirectUri="http://www.baidu.com"
            Enable="true" />
    
        <!-- ShareByAppClient标识是否使用微博client分享。默认是false -->
        <QZone
            Id="3"
            SortId="3"
            AppId="100371282"
            AppKey="aed9b0303e3ed1e27bae87c33761161d"
            ShareByAppClient="true"
            Enable="true" />
        
        <!-- 
        	Wechat微信和WechatMoments微信朋友圈的appid是一样的;
        
                           注意:开发人员不能用我们这两个平台的appid,否则分享不了
        
           	  微信測试的时候,微信測试须要先签名打包出apk,
    		sample測试微信,要先签名打包,keystore在sample项目中,password123456
    		
    		BypassApproval是绕过审核的标记。设置为true后AppId将被忽略,故不经过
    		审核的应用也能够运行分享,可是仅限于分享文字和图片,不能分享其它类型,
    		默认值为false。此外。微信收藏不支持此字段。
    	-->
        <Wechat
            Id="4"
            SortId="4"
            AppId="wx4868b35061f87885"
            AppSecret="64020361b8ec4c99936c0e3999a9f249"
            BypassApproval="false"
            Enable="true" />
        
        <WechatMoments
            Id="5"
            SortId="5"
            AppId="wx4868b35061f87885"
            AppSecret="64020361b8ec4c99936c0e3999a9f249"
            BypassApproval="true"
            Enable="true" />
            
    	<WechatFavorite
            Id="6"
            SortId="6"
            AppId="wx4868b35061f87885"
            AppSecret="64020361b8ec4c99936c0e3999a9f249"
            Enable="true" />
        
    	<!-- ShareByAppClient标识是否使用微博client分享。默认是false -->
    	<QQ
            Id="7"
            SortId="7"
            AppId="100371282"
            AppKey="aed9b0303e3ed1e27bae87c33761161d"
            ShareByAppClient="true"
            Enable="true" />
        
        <Facebook
            Id="8"
            SortId="8"
            ConsumerKey="107704292745179"
            ConsumerSecret="38053202e1a5fe26c80c753071f0b573"
            Enable="true" />
    
        <Twitter
            Id="9"
            SortId="9"
            ConsumerKey="mnTGqtXk0TYMXYTN7qUxg"
            ConsumerSecret="ROkFqr8c3m1HXqS3rm3TJ0WkAJuwBOSaWhPbZ9Ojuc"
            CallbackUrl="http://www.sharesdk.cn"
            Enable="true" />
    
        <Renren
            Id="10"
            SortId="10"
            AppId="226427"
            ApiKey="fc5b8aed373c4c27a05b712acba0f8c3"
            SecretKey="f29df781abdd4f49beca5a2194676ca4"
            Enable="true" />
        
        <KaiXin
            Id="11"
            SortId="11"
            AppKey="358443394194887cee81ff5890870c7c"
            AppSecret="da32179d859c016169f66d90b6db2a23"
            RedirectUri="http://www.sharesdk.cn"
            Enable="true" />
        
        <Email
            Id="12" 
            SortId="12"
            Enable="true" />
        
        <ShortMessage
            Id="13" 
            SortId="13"
            Enable="true" />
        
        <SohuMicroBlog
            Id="14"
            SortId="14"
            ApiKey="q70QBQM9T0COxzYpGLj9"
            ConsumerKey="q70QBQM9T0COxzYpGLj9"
            ConsumerSecret="XXYrx%QXbS!uA^m2$8TaD4T1HQoRPUH0gaG2BgBd"
            CallbackUrl="http://www.sharesdk.cn"
            Enable="true" />
    	
        <NetEaseMicroBlog
            Id="15"
            SortId="15"
            ConsumerKey="T5EI7BXe13vfyDuy"
            ConsumerSecret="gZxwyNOvjFYpxwwlnuizHRRtBRZ2lV1j"
            RedirectUri="http://www.shareSDK.cn"
            Enable="true" />
        
        <Douban
            Id="16"
            SortId="16"
            ApiKey="02e2cbe5ca06de5908a863b15e149b0b"
            Secret="9f1e7b4f71304f2f"
            RedirectUri="http://www.sharesdk.cn"
            Enable="true" />
        
        <YouDao
            Id="17"
            SortId="17"
            HostType="product"
            ConsumerKey="dcde25dca105bcc36884ed4534dab940"
            ConsumerSecret="d98217b4020e7f1874263795f44838fe"
            RedirectUri="http://www.sharesdk.cn"
            Enable="true" />
            
    	<SohuSuishenkan
            Id="18"
            SortId="18"
            AppKey="e16680a815134504b746c86e08a19db0"
            AppSecret="b8eec53707c3976efc91614dd16ef81c"
            RedirectUri="http://sharesdk.cn"
            Enable="true" />
            
        <!-- 
        	在中国大陆,印象笔记有两个server,一个是沙箱(sandbox),一个是生产server(china)。

    一般你注冊应用,它会先让你使用sandbox,当你完毕測试以后。能够到 http://dev.yinxiang.com/support/上激活你的ConsumerKey。激活成功后。改动HostType 为china就好了。

    至于假设您申请的是国际版的印象笔记(Evernote)。则其生产server类型为 “product”。 假设目标设备上已经安装了印象笔记client,ShareSDK同意应用调用本地API来完毕分享,但 是须要将应用信息中的“ShareByAppClient”设置为true,此字段默认值为false。 --> <Evernote Id="19" SortId="19" HostType="sandbox" ConsumerKey="sharesdk-7807" ConsumerSecret="d05bf86993836004" ShareByAppClient="false" Enable="true" /> <LinkedIn Id="20" SortId="20" ApiKey="ejo5ibkye3vo" SecretKey="cC7B2jpxITqPLZ5M" RedirectUrl="http://sharesdk.cn" Enable="true" /> <GooglePlus Id="21" SortId="21" Enable="true" /> <FourSquare Id="22" SortId="22" ClientID="G0ZI20FM30SJAJTX2RIBGD05QV1NE2KVIM2SPXML2XUJNXEU" ClientSecret="3XHQNSMMHIFBYOLWEPONNV4DOTCDBQH0AEMVGCBG0MZ32XNU" RedirectUrl="http://www.sharesdk.cn" Enable="true" /> <Pinterest Id="23" SortId="23" ClientId="1432928" Enable="true" /> <Flickr Id="24" SortId="24" ApiKey="33d833ee6b6fca49943363282dd313dd" ApiSecret="3a2c5b42a8fbb8bb" RedirectUri="http://www.sharesdk.cn" Enable="true" /> <Tumblr Id="25" SortId="25" OAuthConsumerKey="2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM" SecretKey="3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo" CallbackUrl="http://sharesdk.cn" Enable="true" /> <Dropbox Id="26" SortId="26" AppKey="7janx53ilz11gbs" AppSecret="c1hpx5fz6tzkm32" Enable="true" /> <VKontakte Id="27" SortId="27" ApplicationId="3921561" Enable="true" /> <Instagram Id="28" SortId="28" ClientId="ff68e3216b4f4f989121aa1c2962d058" ClientSecret="1b2e82f110264869b3505c3fe34e31a1" RedirectUri="http://sharesdk.cn" Enable="true" /> <!-- Yixin易信和YixinMoments易信朋友圈的appid是一样的; 注意:开发人员不能用我们这两个平台的appid,否则分享不了 易信測试的时候须要先签名打包出apk, sample測试易信。要先签名打包,keystore在sample项目中,password123456 BypassApproval是绕过审核的标记,设置为true后AppId将被忽略,故不经过 审核的应用也能够运行分享。可是仅限于分享文字或图片,不能分享其它类型, 默认值为false。 --> <Yixin Id="29" SortId="29" AppId="yx0d9a9f9088ea44d78680f3274da1765f" BypassApproval="true" Enable="true" /> <YixinMoments Id="30" SortId="30" AppId="yx0d9a9f9088ea44d78680f3274da1765f" BypassApproval="true" Enable="true" /> <Mingdao Id="31" SortId="31" AppKey="EEEE9578D1D431D3215D8C21BF5357E3" AppSecret="5EDE59F37B3EFA8F65EEFB9976A4E933" RedirectUri="http://sharesdk.cn" Enable="true" /> <Line Id="32" SortId="32" Enable="true" /> <KakaoTalk Id="33" SortId="33" Enable="true" /> <KakaoStory Id="34" SortId="34" Enable="true" /> </DevInfor>





    须要的包:如图:



  • 相关阅读:
    Ubuntu Server 18.04上安装fail2ban
    Spring Security实现用户名密码登录
    Spring Boot集成H2数据库
    2019年过去了,我很怀念它
    基于Spring Boot的统一异常处理设计
    Git推送到多个远程仓库
    广州商学院16级软工一班&二班-助教总结
    记一次返工之后记
    广州商学院16级软工一班&二班-第四次作业成绩
    广州商学院16级软工一班&二班-第三次作业成绩
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6849537.html
Copyright © 2011-2022 走看看