Back

shareSDK java ThirdPartyLogin源代码的运行方式

发布时间: 2015-04-12 06:08:00

refer to:  https://github.com/ShareSDKPlatform/ThirdPartyLoginDemo

这个源代码很好,可以运行。唯一不足的是没有提供编译的脚本。 对刚接触的朋友有一定的困扰。

所以:

1. 新建一个项目: 

# 先看 android 
$ android list targets
# 再找个你认为可以作为target的版本,比如我的是8 
$ android create project --target 8 --name MyFirstApp --path . --activity MainActivity --package com.happysoft

2. 把上面步骤生成的几个配置文件COPY过来:

$ cp local.properties ../ThirdPartyLoginDemo
$ cp ant.properties ../ThirdPartyLoginDemo
$ cp build.xml ../ThirdPartyLoginDemo

3. 对它的代码做一定的修改(比如为某个源代码机上几句 System.out.println 之后,比如如下:\

),就可以编译了:

  // src/cn/sharesdk/tpl/ThirdPartyLogin.java
  public void onComplete(Platform platform, int action, HashMap res) {
    System.out.println("==== in onComplete" + res);
    System.out.println("== "+ "== authorize done");
    System.out.println("== "+ "== now get platformDb");
    PlatformDb platformDb = platform.getDb();
    System.out.println("== exportData: "+ platformDb.exportData());
    System.out.println("== getToken:"+ platformDb.getToken());

    System.out.println("== platformDb.isValid()");
    System.out.println(platformDb.isValid());
    System.out.println("== userid: "+ platformDb.getUserId());
    System.out.println("== expiresIn: "+ platformDb.getExpiresIn()+"");
    System.out.println("== getPlatformNname: "+ platformDb.getPlatformNname());
    System.out.println("== getPlatformVersion: "+ platformDb.getPlatformVersion()+"");
    System.out.println("== getUserIcon"+ platformDb.getUserIcon());
    System.out.println("============");
    System.out.println("== done: get platformDb");
    if (action == Platform.ACTION_USER_INFOR) {
      Message msg = new Message();
      msg.what = MSG_AUTH_COMPLETE;
      msg.obj = new Object[] {platform.getName(), res};
      handler.sendMessage(msg);
    }
  }

编译:

$ ant debug

4. 把生成的apk文件 安装到手机上

$ adb install bin/MyFirstApp-debug.apk 

如果安装不了的话也不怕, 使用 adb push到手机上,然后打开文件夹,手动安装:

# 先人肉进入到手机的文件夹, 随便找一个文件,长按,点击 “详情”,就可以看到这个文件的所在路径,比如
# /storage/sdcard0
$ adb push bin/ooxx.apk /storage/sdcard0
# 然后再安装

最后,运行 app, 然后 $ adb shell logcat 查看日志。

比如:

# 点击 微博登录 后:

I/System.out( 9083): ==== in authorize 1
I/System.out( 9083): ==== in authorize 2, before setPlatformActionListener
I/System.out( 9083): ==== in authorize 3. closing SSOSetting
I/System.out( 9083): ==== in authorize 4. showUser(null)
I/System.out( 9083): ==== in authorize 5. done showUser(null)
I/System.out( 9083): ==== in onComplete{verified_source_url=, location=北京 朝阳区, remark=, block_app=0, verified_type=-1, verified_reason=, statuses_count=208, verified_source=, lang=zh-cn, city=5, credit_score=80, id=1408666544, verified_trade=, following=false, favourites_count=11, idstr=1408666544, description=以程序糊口,以学习修身。, verified=false, name=申思维, province=11, domain=sg552sg552, gender=m, created_at=Tue Nov 02 17:01:31 +0800 2010, weihao=, followers_count=139, online_status=0, profile_url=sg552sg552, bi_followers_count=67, geo_enabled=false, status={text=新浪微博Android客户端V3.3.5全新升级!支持在线主题下载,精美主题不容错过;全新话题功能,参与话题讨论更快捷!下载地址:http://t.cn/zTfKi4x, pic_urls=[], comments_count=0, source_allowclick=0, visible={type=0, list_id=0}, attitudes_count=0, darwin_tags=[], in_reply_to_screen_name=, mlevel=0, source_type=1, truncated=false, id=3776161362477533, idstr=3776161362477533, source=微博客户端, favorited=false, in_reply_to_status_id=, created_at=Wed Nov 12 19:08:09 +0800 2014, in_reply_to_user_id=, reposts_count=0, mid=3776161362477533}, star=0, class=1, urank=16, allow_all_comment=true, avatar_hd=http://tp1.sinaimg.cn/1408666544/180/40016969148/1, mbrank=0, allow_all_act_msg=false, url=http://siwei.me, avatar_large=http://tp1.sinaimg.cn/1408666544/180/40016969148/1, pagefriends_count=0, friends_count=128, verified_reason_url=, screen_name=申思维, mbtype=0, profile_image_url=http://tp1.sinaimg.cn/1408666544/50/40016969148/1, follow_me=false, block_word=0, ptype=0}
I/System.out( 9083): == == authorize done
I/System.out( 9083): == == now get platformDb
I/System.out( 9083): == exportData: {"secretType":"0","icon":"http:\/\/tp1.sinaimg.cn\/1408666544\/180\/40016969148\/1","remind_in":"652976","nickname":"申思维","expiresIn":652976,"expiresTime":1428817023980,"shareCount":"208","snsUserUrl":"http:\/\/weibo.com\/sg552sg552","resume":"以程序糊口,以学习修身。","snsregat":"1288688491000","token":"2.00IWc1XB0H7CVc60cd8b5de0gkIKrC","favouriteCount":"128","gender":"0","secret":"","followerCount":"139","weibo":"1408666544"}
I/System.out( 9083): == getToken:2.00IWc1XB0H7CVc60cd8b5de0gkIKrC
I/System.out( 9083): == platformDb.isValid()
I/System.out( 9083): == userid: 1408666544
I/System.out( 9083): == expiresIn: 652976
I/System.out( 9083): == getPlatformNname: SinaWeibo
I/System.out( 9083): == getPlatformVersion: 1
I/System.out( 9083): == getUserIconhttp://tp1.sinaimg.cn/1408666544/180/40016969148/1
I/System.out( 9083): ============
I/System.out( 9083): == done: get platformDb
E/picturePath ==>>( 9083): /storage/sdcard0/cn.sharesdk.demo.tpl/download/userIcon.jpg



# 点击 QQ 登录后:

I/System.out( 9083): ==== in authorize 1
I/System.out( 9083): ==== in authorize 2, before setPlatformActionListener
I/System.out( 9083): ==== in authorize 3. closing SSOSetting
I/System.out( 9083): ==== in authorize 4. showUser(null)
I/System.out( 9083): ==== in authorize 5. done showUser(null)
I/System.out( 9083): ==== in onComplete{ret=0, is_yellow_year_vip=0, figureurl_qq_1=http://q.qlogo.cn/qqapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/40, nickname=思维, figureurl_qq_2=http://q.qlogo.cn/qqapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/100, yellow_vip_level=0, is_lost=0, msg=, city=朝阳, figureurl_1=http://qzapp.qlogo.cn/qzapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/50, vip=0, figureurl_2=http://qzapp.qlogo.cn/qzapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/100, level=0, province=北京, gender=男, is_yellow_vip=0, figureurl=http://qzapp.qlogo.cn/qzapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/30}
I/System.out( 9083): == == authorize done
I/System.out( 9083): == == now get platformDb
I/System.out( 9083): == exportData: {"secretType":"0","icon":"http:\/\/qzapp.qlogo.cn\/qzapp\/100371282\/B5BB36F4766F3DC1F48E89231F232E5B\/100","nickname":"思维","token":"FD76D629467CC34057C4154B851B9602","expiresIn":7776000,"expiresTime":1428817785437,"iconQQ":"http:\/\/q.qlogo.cn\/qqapp\/100371282\/B5BB36F4766F3DC1F48E89231F232E5B\/40","gender":"0","secret":"","weibo":"B5BB36F4766F3DC1F48E89231F232E5B"}
I/System.out( 9083): == getToken:FD76D629467CC34057C4154B851B9602
I/System.out( 9083): == platformDb.isValid()
I/System.out( 9083): == userid: B5BB36F4766F3DC1F48E89231F232E5B
I/System.out( 9083): == expiresIn: 7776000
I/System.out( 9083): == getPlatformNname: QZone
I/System.out( 9083): == getPlatformVersion: 2
I/System.out( 9083): == getUserIconhttp://qzapp.qlogo.cn/qzapp/100371282/B5BB36F4766F3DC1F48E89231F232E5B/100
I/System.out( 9083): ============
I/System.out( 9083): == done: get platformDb
E/picturePath ==>>( 9083): /storage/sdcard0/cn.sharesdk.demo.tpl/download/userIcon.jpg

Back