求新浪微博oauth2.0能用的登录代码

解决方案 »

  1.   

    我自己半个月前集成sinaSDk一个oauth2.0  分享新浪微博的源码,可以到我的资源里面去看看、
      

  2.   

    http://code.google.com/p/android-weibo-sdk/downloads/list官方SDK,带一个垃圾无比的登录Demo的。
      

  3.   


    /**
     * 新浪微博授权
     * 
     * @param activity 上下文
     * 
     * @param listener 授权结束后的回调
     * 
     * */
    public void gotoWeiboOauth(Activity activity,WeiboDialogListener listener) throws Exception{
    Weibo weibo = null;
    try {
    weibo = Weibo.getInstance();
    weibo.setRedirectUrl(UrlUtils.URL_WEIBO_CALLBACK);  //后台回调地址
    weibo.setupConsumerConfig(StringUtils.CONSUMER_KEY, StringUtils.CONSUMER_SECRET);
    if(listener == null){
    throw new Exception("The listener can not be null");
    }
    weibo.authorize(activity, listener);
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    throw e;

    }finally{

    }
    }

    /**
     * 将内容分享到微博
     * 
     * @param activity 上下文
     * 
     * @param content 待分享内容
     * 
     * @param imagePath 待分享图片路径
     * 
     * */
    public void shareToWeibo(Activity activity,String content,String imagePath){
    Weibo weibo = null;
    AccessToken token = null;
    try {
    weibo = Weibo.getInstance();
    if(accessToken != null){
    token = new AccessToken(accessToken, StringUtils.CONSUMER_SECRET);
    token.setExpiresIn(expiresIn);
    weibo.setAccessToken(token);
    }
            weibo.share2weibo(activity, weibo.getAccessToken().getToken(), weibo.getAccessToken()
                    .getSecret(), content, null);
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    }几天前写的,没做token过期处理,这段代码也没有保存token,需要自己写保存、过期等逻辑