├── .gitattributes ├── .gitignore ├── AndroidManifest.xml ├── README.md ├── gen └── cstdr │ └── weibosdk │ └── demo │ ├── BuildConfig.java │ └── R.java ├── libs ├── SinaWeiboSDK.jar ├── TencentWeiboSDK.jar ├── TencentWeiboSDKComponent.jar ├── android-support-v4.jar └── commons-httpclient-3.0.1.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── layout │ └── main.xml ├── menu │ └── activity_main.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml └── values │ ├── strings.xml │ └── styles.xml └── src └── cstdr └── weibosdk └── demo ├── MainActivity.java ├── share ├── Constants.java ├── SinaWeiboAPI.java ├── SinaWeiboUtil.java ├── TencentTO.java ├── TencentWebAuthActivity.java ├── TencentWeiboAPI.java └── TencentWeiboUtil.java └── util ├── LOG.java ├── PreferenceUtil.java └── Util.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 新浪微博、腾讯微博开放平台DEMO(WeiboSDKDemo) 2 | 3 | > ####20140105 因为新浪官方微博更新频繁,并且现在新浪的文档比较完善,建议大家先浏览[新浪官方GitHub][SinaWeiboGitHub]~ 4 | 5 | * 最近学习开放平台,官方文档和Demo有点坑爹,经过几天的努力,写了一个DEMO,整合了新浪微博和腾讯微博,均能够SSO授权、网页授权和发微博,如果需要可以去看看源码,里面有注释说明 6 | * 代码使用自己感觉舒服的方式进行封装和整合,使用前需要修改的地方在下面有详细说明,如果有问题请随时联系我,或者咱们一起完善!~ 7 | * 代码并没有整合所有API方法(其实我觉得这也没必要),当你需要哪个API接口,可以马上去官网查看API文档(文档也会变的),然后添加上去就可以啦~ 8 | 9 | * 官方新浪微博SDK地址:https://github.com/mobileresearch/weibo_android_sdk 10 | * 新浪API文档:http://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI 11 | 12 | * 官方腾讯微博SDK地址:http://wiki.open.t.qq.com/index.php/%E7%A7%BB%E5%8A%A8%E5%BA%94%E7%94%A8%E6%8E%A5%E5%85%A5 13 | * 腾讯API文档:http://wiki.open.t.qq.com/index.php/API%E6%96%87%E6%A1%A3 14 | 15 | *** 16 | 17 | ### WeiboSDKDemo使用方法 18 | 19 | * 请先熟悉官方文档,虽然其中有一些问题:) 20 | * 根据文档申请开放平台帐号,特别注意回调地址,官网和代码中要保持一致,这个经常出现错误; 21 | * 运行Demo前,先确定下载完Demo的所有文件,有关jar包的问题可以参考官方文档,都是必须的依赖包; 22 | * 然后修改开放平台的AppKey和AppSecret: 23 | 24 | 1. 新浪微博需要在Constants类中把appkey、appsecret修改成自己应用对应的appkey和appsecret,回调地址不需要修改; 25 | 1. 腾讯微博需要修改配置文件,目标文件config.properties在Android_SDK.jar包config文件夹下(我已经改名为TencentWeiboSDK.jar),把appkey、appsecret修改成自己应用对应的appkey和appsecret,这里再次提醒注意回调地址要和网上你填写的一致,别管文档怎么说. 26 | 27 | * 修改完后,clean工程,运行测试吧! 28 | 29 | ### 网友反馈QA 30 | 31 | * 特别注意! 32 | 33 | 如果使用Eclipse无法直接导入工程,请新建一个工程,将代码资源等复制到新工程,再根据上面的步骤修改AppKey等内容~ 34 | 35 | * (20131024)Q:新浪微博SSO授权无法正常授权,我是新注册的开发者账号。 36 | > A:根据最新的官方文档,原因应该是没有在网站注册包名和签名,注册步骤可以参考官方文档,不多说啦~ 37 | 38 | * (20130901)Q:新浪微博SSO授权还让输入一次账号密码。 39 | > A:这是我自己使用的时候发现的,用公司审核过的APP可以直接SSO授权不会再次输入,也许这就是原因吧~(请参考20131024的反馈) 40 | 41 | * (20130830)Q:新浪微博SSO正常,但是网页授权不成功。 42 | > A:最近也有几个开发者反馈给我,同样的代码,用我以前申请的账号的Key可以授权成功,开发者新申请的账号Key却不能,一个开发者用其他Demo可以正常授权,猜想是SDK版本不同导致的授权问题,我目前的Demo使用的是3个月前的SDK,周末会更新到最新SDK,期待到时候问题会解决~(已经更新到最新SDK0821)(请参考20131024的反馈) 43 | 44 | * (20130819)Q:新浪微博我都按照文档设置了,为啥还是获取不到token? 45 | > A:也许是你没有设置“测试账号”,“管理中心”->左面的“应用信息”->“测试账号”,已关联测试帐号只能添加15个人~ 46 | 47 | * (20130629)Q:导入工程后点击腾讯微博授权(没有安装腾讯微博客户端),结果报错找不到类TencentWebAuthActivity? 48 | > A:请到Manifest文件重新设置改类的路径地址~ 49 | 50 | * (20130625)Q:新浪微博的回调地址在哪里设置? 51 | > A:“管理中心”->左面的“应用信息”->“高级信息”->左面的“授权回调页”,就是这个地方,使用代码中的默认地址(https://api.weibo.com/oauth2/default.html )即可,注意保持一致~ 52 | 53 | * (20130619)Q:腾讯微博的jar包如何修改Appkey等参数? 54 | > A:不能在Eclipse中打开,要到项目的目录下用任何解压缩工具打开jar包并修改config.properties文件然后保存即可~ 55 | 56 | * (20130604)Q:腾讯微博的回调地址在哪里设置? 57 | > A:“管理中心”->“基本信息”->“应用地址”,就是这个地方,注意保持一致~ 58 | 59 | 感谢大家的反馈和建议!~ 60 | 61 | 下面是我自己的一点总结,如果你有好的建议,请分享下吧~ 62 | 63 | *** 64 | 65 | ### 新浪微博平台: 66 | 67 | * SSO一直没有测试成功,运行官方DEMO也如此,没有找到解决方法,已经确认是新浪的问题,没有开放大量注册,官方建议先使用老版本SDK ;今天发现新浪更新了文档和jar包,SSO可以正常使用,返回Token、uid、userName等信息; 68 | * SSO和网页授权得到的都是授权Code,不是Token,所以还需要根据Code去获取Token,调用getAccessTokenByCode 方法利用官方API接口获取到Token; 69 | * 目前网页授权、微博分享都操作已经整合到工程中,测试正常; 70 | * 新浪另一个问题,token过期后需要用户登陆重新授权。 71 | 72 | ### 新浪SSO授权返回值:(缺少UserName,所以授权后再去获取了一次取) 73 | 74 | 1. key = uid value = 1111111111 ; 75 | 1. key = userName value = cstdr ;(最新SDK0821已经没有返回这个字段) 76 | 1. key = expires_in value = 157186399 ; 77 | 1. key = remind_in value = 157186399 ; 78 | 1. key = access_token value = 2.00KNDUIDyonFnC99e5598a960gYir2 。 79 | 80 | ### 新浪网页授权返回值:(缺少UserName,所以授权后再去获取了一次) 81 | 82 | 1. key = uid value = 1111111111 ; 83 | 1. key = expires_in value = 157185966 ; 84 | 1. key = remind_in value = 157185966 ; 85 | 1. key = access_token value = 2.00KNDUIDyonFnC99e5598a960gYir2 。 86 | 87 | *** 88 | 89 | ### 腾讯微博平台: 90 | 91 | * SSO可以正常获取; 92 | * 因为获取授权时Refreshtoken 总为null,所以不能使用官方SDK自带方法,于是把新浪微博的方法修改,使之适用于腾讯微博; 93 | * 回调地址文档说可以为空,但是实际上为空不能网页授权,必须与网站上填写的一致,否则分享微博的时候总是说回调地址错误,所以重新修改了网页授权的Activity; 94 | * 网页授权的Activity不仅仅是回调地址为空问题,还因为没有回调方法,不能得到授权正确与否的消息,也就不能修改UI和数据,所以修改后添加了回调方法。 95 | 96 | ### 腾讯SSO授权返回值:(返回WeiboToken ,但是缺少UserName,还需要再获取一次) 97 | 98 | 1. token.accessToken = 8e509ffc2cbad04e1678d9e2b1822970 ; 99 | 1. token.expiresIn = 604800 ; 100 | 1. token.omasKey = 9a23c968893edb64fc35fa33f7b44c05 ; 101 | 1. token.omasToken = 010000008790cc668e6ed810b2cffc374f9a3dd9ed126be4a279eff1c0c1a6852ea048019c4c6746cb40ce72 ; 102 | 1. token.openID = 5789a9d103704e1f63102b1dba348690 ;(即uid) 103 | 1. token.refreshToken = 。(总为空) 104 | 105 | ### 腾讯网页授权返回值:(所需全有,不用再获取) 106 | 107 | 1. accessToken = 8e509ffc2cbad04e1678d9e2b1822970 ; 108 | 1. expiresIn = 8035200 ; 109 | 1. omasKey = 090FF697B85D63703AAA4AB6642650EB ; 110 | 1. openID = 5789A9D103704E1F63102B1DBA348690 ; 111 | 1. refreshToken = 359107cbc9f7a43b69ccaaafadf14ff1 ; 112 | 1. state = 111 ; 113 | 1. name = name ; 114 | 1. nick = nick 。 115 | 116 | *** 117 | 118 | ## 联系或反馈 119 | 120 | 如果你有任何问题、建议或者想交个朋友,请联系我吧~ 121 | 122 | 我的邮箱: cstdingran(at)gmail.com (讨论问题请通过邮件) 123 | 124 | 125 | [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/cstdr/weibosdkdemo/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 126 | 127 | [SinaWeiboGitHub]:https://github.com/mobileresearch/weibo_android_sdk 128 | -------------------------------------------------------------------------------- /gen/cstdr/weibosdk/demo/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package cstdr.weibosdk.demo; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /gen/cstdr/weibosdk/demo/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package cstdr.weibosdk.demo; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class drawable { 14 | public static final int ic_launcher=0x7f020000; 15 | } 16 | public static final class id { 17 | public static final int btn_add_sina=0x7f070008; 18 | public static final int btn_add_tx=0x7f070003; 19 | public static final int btn_auth_sina=0x7f070007; 20 | public static final int btn_auth_tx=0x7f070002; 21 | public static final int btn_logout_sina=0x7f070009; 22 | public static final int btn_logout_tx=0x7f070004; 23 | public static final int menu_settings=0x7f07000a; 24 | public static final int tv_auth_sina=0x7f070005; 25 | public static final int tv_auth_tx=0x7f070000; 26 | public static final int tv_token_sina=0x7f070006; 27 | public static final int tv_token_tx=0x7f070001; 28 | } 29 | public static final class layout { 30 | public static final int main=0x7f030000; 31 | } 32 | public static final class menu { 33 | public static final int activity_main=0x7f060000; 34 | } 35 | public static final class string { 36 | public static final int app_name=0x7f040000; 37 | public static final int hello_world=0x7f040001; 38 | public static final int menu_settings=0x7f040002; 39 | } 40 | public static final class style { 41 | /** 42 | Base application theme, dependent on API level. This theme is replaced 43 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 44 | 45 | 46 | Theme customizations available in newer API levels can go in 47 | res/values-vXX/styles.xml, while customizations related to 48 | backward-compatibility can go here. 49 | 50 | 51 | Base application theme for API 11+. This theme completely replaces 52 | AppBaseTheme from res/values/styles.xml on API 11+ devices. 53 | 54 | API 11 theme customizations can go here. 55 | 56 | Base application theme for API 14+. This theme completely replaces 57 | AppBaseTheme from BOTH res/values/styles.xml and 58 | res/values-v11/styles.xml on API 14+ devices. 59 | 60 | API 14 theme customizations can go here. 61 | */ 62 | public static final int AppBaseTheme=0x7f050000; 63 | /** Application theme. 64 | All customizations that are NOT specific to a particular API-level can go here. 65 | */ 66 | public static final int AppTheme=0x7f050001; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /libs/SinaWeiboSDK.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/libs/SinaWeiboSDK.jar -------------------------------------------------------------------------------- /libs/TencentWeiboSDK.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/libs/TencentWeiboSDK.jar -------------------------------------------------------------------------------- /libs/TencentWeiboSDKComponent.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/libs/TencentWeiboSDKComponent.jar -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/libs/android-support-v4.jar -------------------------------------------------------------------------------- /libs/commons-httpclient-3.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/libs/commons-httpclient-3.0.1.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cstdr/WeiboSDKDemo/572ca4c79ededc39fe71cd516044ef78c74aac32/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | 25 | 26 |