在Unity项目中接入ShareSDK
2015-06-27 19:33
459 查看
1、上ShareSDK的官网"http://mob.com/"注册一个开发者账号以及下载ShareSDK的包
2、在ShareSDK的官网上注册你的app,将会得到一个app_key和app_secret。将在后面的代码中使用到。
3、根据"http://wiki.mob.com/Unity3D快速集成指南/"所说的步骤接入SDK
4、接下来上代码:
上面程序的用法在“Unity3D快速集成指南”中都有提及的。
主要是几个地方需要注意
a)、ShareSDK.open("85eca69c8782");这里的参数就是你在sharesdk官网注册你的app的那个app_key
b)、每个平台需要设置的内容有些许差异,需要设置的内容请参考《社交平台配置项说明》文档”http://wiki.mob.com/社交平台配置项说明/“。对于每个平台,都需要到对应的平台注册你当前的这个应用的信息以获得在相应平台的app_id或者app_key,app_secret.这样才能在程序中对平台信息进行设置。
C)、我在接完ShareSDK后打包成APK,安装到手机之后以为成功了,谁知道一运行就闪退了,后面用Cygwin64Terminal查看了一下日志才知道主Activity没有找到,
找了安卓的配置文件里面的配置都是正确的,最后的解决办法是,在下载下来的ShareSDK的项目中有个Android_Java_Demo项目,使用Eclipse将此项目打开,然后对src右键->Export->class->jar
file,然后将导出的文件命名为OneKeyShare,然后替换在Unity工程中的Asset->Plugins->Android->libs下的OneKeyShare就解决了,我猜测可能是api版本的问题,不知是不是,有知道的小伙伴请知会我一声,谢谢!
ps:
各个平台注册应用信息的地址如下:
新浪微博 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://developer.linkedin.com 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/ Pocket http://getpocket.com/developer/apps/new
2、在ShareSDK的官网上注册你的app,将会得到一个app_key和app_secret。将在后面的代码中使用到。
3、根据"http://wiki.mob.com/Unity3D快速集成指南/"所说的步骤接入SDK
4、接下来上代码:
void Start () { ShareSDK.setCallbackObjectName("Main Camera"); ShareSDK.open("85eca69c8782"); //在shareSDK官网上的注册的app的app_key Hashtable weixinConf = new Hashtable(); weixinConf.Add("app_id", "wx4868b35061f87885"); //ShareSDK.setPlatformConfig(PlatformType.WeChatSession, weixinConf); //微信朋友圈 ShareSDK.setPlatformConfig(PlatformType.WeChatTimeline, weixinConf); //ShareSDK.setPlatformConfig(PlatformType.WeChatFav, weixinConf); //QQ Hashtable qqConf = new Hashtable(); qqConf.Add("app_id", "1104666957"); ShareSDK.setPlatformConfig(PlatformType.QQ, qqConf); //QZone Hashtable qzConf = new Hashtable(); qzConf.Add("app_id", "1104666957"); qzConf.Add("app_key", "Roh1JgeVpfwmKR35"); ShareSDK.setPlatformConfig(PlatformType.QZone, qzConf); //拷贝本地图片 string imagePath = Application.persistentDataPath + "/0.png"; if(!System.IO.File.Exists(imagePath)) { Texture2D texture = Resources.Load("0") as Texture2D; System.IO.File.WriteAllBytes(imagePath, texture.EncodeToPNG()); } } public void ShareWeiXinMessage() { Hashtable content = new Hashtable(); content["title"] = "Cris的测试项目"; content["content"] = "只是测试而已,可以忽略!!!"; string imagePath = Application.persistentDataPath + "/0.png"; if (System.IO.File.Exists(imagePath)) { content["image"] = imagePath; } content["url"] = "www.baidu.com"; content["type"] = Convert.ToString((int)ContentType.News); ShareResultEvent evt = new ShareResultEvent(ShareResultHandler); //ShareSDK.shareContent(PlatformType.WeChatTimeline, content, evt); ShareSDK.showShareMenu(null, content, 100, 100, MenuArrowDirection.Up, evt); } void ShareResultHandler(ResponseState state, PlatformType type, Hashtable shareInfo, Hashtable error, bool end) { if (state == ResponseState.Success) { print("分享成功"); print(MiniJSON.jsonEncode(shareInfo)); } else if (state == ResponseState.Fail) { print("分享失败"); print("fail! error code = " + error["error_code"] + "; error msg = " + error[ "error_msg"]); } else if (state == ResponseState.Cancel) { print("cancel !"); } }
上面程序的用法在“Unity3D快速集成指南”中都有提及的。
主要是几个地方需要注意
a)、ShareSDK.open("85eca69c8782");这里的参数就是你在sharesdk官网注册你的app的那个app_key
b)、每个平台需要设置的内容有些许差异,需要设置的内容请参考《社交平台配置项说明》文档”http://wiki.mob.com/社交平台配置项说明/“。对于每个平台,都需要到对应的平台注册你当前的这个应用的信息以获得在相应平台的app_id或者app_key,app_secret.这样才能在程序中对平台信息进行设置。
C)、我在接完ShareSDK后打包成APK,安装到手机之后以为成功了,谁知道一运行就闪退了,后面用Cygwin64Terminal查看了一下日志才知道主Activity没有找到,
找了安卓的配置文件里面的配置都是正确的,最后的解决办法是,在下载下来的ShareSDK的项目中有个Android_Java_Demo项目,使用Eclipse将此项目打开,然后对src右键->Export->class->jar
file,然后将导出的文件命名为OneKeyShare,然后替换在Unity工程中的Asset->Plugins->Android->libs下的OneKeyShare就解决了,我猜测可能是api版本的问题,不知是不是,有知道的小伙伴请知会我一声,谢谢!
ps:
各个平台注册应用信息的地址如下:
新浪微博 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://developer.linkedin.com 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/ Pocket http://getpocket.com/developer/apps/new
相关文章推荐
- Kinect结合Unity3D引擎开发体感游戏(一)
- Unity3D中脚本的执行顺序和编译顺序
- Unity3D动态对象优化代码分享
- ShareSDK造成App崩溃的一个BUG原因分析以及Fix方法
- unity3d发布apk在android虚拟机中运行的详细步骤(unity3d导出android apk)
- Cocos2d-x 3.0中集成社交分享ShareSDK的详细步骤和常见问题解决
- Unity3D游戏引擎实现在Android中打开WebView的实例
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- unity实现摄像头跟随
- unity3d调用手机或电脑摄像头
- 分享一个开源的网络游戏服务器架构—HouHai
- Unity3D插件详细评测及教学下载
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- 姜雪伟老师“双旦活动大福利”