ios新浪微博分享

做新浪分享 需先去 http://open.weibo.com/apps 注册开发者app 很简单!
1
ios新浪微博分享(1)
2 ios新浪微博分享(1)
3设置你的应用的信息
ios新浪微博分享(1)
找到自己的appkey
ios新浪微博分享(1)

还需要设置自己的 kAppRedirectURL 测试可以随便写个!
ios新浪微博分享(1)
开发需要下载官方的sdk  http://open.weibo.com/wiki/SDK#iOS_SDK
ios新浪微博分享(2)
本人下载的版本
ios新浪微博分享(2)
新建一个viewcontrroler==WeiBoViewController
效果图  ios新浪微博分享(2) ios新浪微博分享(2)


h文件

#import


#import "SinaWeb/SinaWeibo/SinaWeibo.h"


#import "SinaWeb/SinaWeibo/SinaWeiboRequest.h"


@interface WeiBoViewController :UIViewController<</span>SinaWeiboDelegate,SinaWeiboRequestDelegate>

{

    UIButton *_shareButton;

    

    UITextView *_textView;

    

    UIView *_shareView;

    

    UIActivityIndicatorView *_indicator;}


@property (strong, nonatomic) UIButton *shareButton;


@property (strong, nonatomic) UITextView *textView;


@property (strong, nonatomic) UIView *shareView;


@property (strong, nonatomic) UIActivityIndicatorView *indicator;



@property (readonly, nonatomic) SinaWeibo *sinaWeibo;


- (void) addButton;


- (void) addShareView;


- (void) share:(UIButton*) sender;


- (void) removeShare:(UIButton*) sender;


- (void) sendShare:(UIButton*) sender;


- (void) exitShare:(UIButton*) sender;

@end

m文件


#import "WeiBoViewController.h"

#define kAppKey             @"appkey"

#define kAppSecret          @"appSecret"

#define kAppRedirectURL     @"重定向url"

@interface WeiBoViewController ()


@end


@implementation WeiBoViewController


@synthesize shareButton = _shareButton;

@synthesize textView = _textView;

@synthesize shareView = _shareView;

@synthesize indicator = _indicator;

@synthesize sinaWeibo = _sinaWeibo;


- (SinaWeibo*)sinaWeibo

{

    _sinaWeibo.delegate=self;

    return _sinaWeibo;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    

    _indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    [_indicator setFrame:CGRectMake(0, 0, 50, 50)];

    _indicator.center = self.view.center;

    [self.view addSubview:_indicator];

    

    _sinaWeibo = [[SinaWeibo alloc] initWithAppKey:kAppKey appSecret:kAppSecretappRedirectURI:kAppRedirectURL andDelegate:self];

    

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    

    NSDictionary *sinaWeiboInfo = [defaults objectForKey:@"SinaWeiboAuthData"];

    

    if ([sinaWeiboInfo objectForKey:@"AccessTokenKey"] && [sinaWeiboInfoobjectForKey:@"ExpirationDateKey"] && [sinaWeiboInfo objectForKey:@"UserIDKey"])

    {

        _sinaWeibo.accessToken = [sinaWeiboInfo objectForKey:@"AccessTokenKey"];

        

        _sinaWeibo.expirationDate = [sinaWeiboInfo objectForKey:@"ExpirationDateKey"];

        

        _sinaWeibo.userID = [sinaWeiboInfo objectForKey:@"UserIDKey"];

    }

    


    

    [self addButton];

}


- (void) addButton

{

    _shareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    UIImage*butimg=[UIImage imageNamed:@"button_background@2x.png"];

    UIImage*logobutimg=[UIImage imageNamed:@"logo@2x.png"];

    [self.shareButton setFrame:CGRectMake(1010, butimg.size.width, butimg.size.height)];

    [self.shareButton setBackgroundImage:butimg forState:UIControlStateNormal];

    [self.shareButton setImage:logobutimg forState:UIControlStateNormal];

    

    [self.shareButton addTarget:self action:@selector(share:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:self.shareButton];

}


//分享按钮响应方法

- (void) share:(UIButton*) sender

{

    SinaWeibo *sinaWeibo = [self sinaWeibo];

    

    BOOL authValid = sinaWeibo.isAuthValid;

    

    if (!authValid)

    {

        [sinaWeibo logIn];

    }

    else

    {

        NSString *postStatusText = @"[哈哈]";

        

        SinaWeibo *sinaWeibo = [self sinaWeibo];

        //只发送汉字

//        [sinaWeibo requestWithURL:@"statuses/update.json" params:[NSMutableDictionary dictionaryWithObjectsAndKeys:postStatusText,@"status", nil] httpMethod:@"POST" delegate:self];

//图片和连接 和文字

        [sinaWeibo requestWithURL:@"statuses/upload.json"

                           params:[NSMutableDictionary dictionaryWithObjectsAndKeys:

                                   @"要发布的微博文本内容,超链接http://baidu.com", @"status",

                                   [UIImage imageNamed:@"Icon.png"], @"pic"nil]

                       httpMethod:@"POST"

                         delegate:self];

        

        [_shareView removeFromSuperview];

        

        [self.indicator startAnimating];

    }

    

}


//登陆成功后回调方法

- (void) sinaweiboDidLogIn:(SinaWeibo *)sinaweibo

{

    NSLog(@"%@--%@--%@--%@",sinaweibo.accessToken,sinaweibo.expirationDate, sinaweibo.userID,sinaweibo.refreshToken);

    NSDictionary *authData = [NSDictionary dictionaryWithObjectsAndKeys:

                              sinaweibo.accessToken@"AccessTokenKey",

                              sinaweibo.expirationDate@"ExpirationDateKey",

                              sinaweibo.userID@"UserIDKey",

                              sinaweibo.refreshToken@"refresh_token"nil];

    [[NSUserDefaults standardUserDefaults] setObject:authData forKey:@"SinaWeiboAuthData"];

    [[NSUserDefaults standardUserDefaults] synchronize];

//可以在此选在授权成功后直接发送

}


//取消按钮回调方法

- (void) removeShare:(UIButton*) sender

{

    [_shareView removeFromSuperview];

}


//发送按钮回调方法

- (void) sendShare:(UIButton*) sender

{

    NSString *postStatusText = self.textView.text;

    

    SinaWeibo *sinaWeibo = [self sinaWeibo];

    

    [sinaWeibo requestWithURL:@"statuses/updates.json" params:[NSMutableDictionarydictionaryWithObjectsAndKeys:postStatusText,@"status"nilhttpMethod:@"POST" delegate:self];

    

    [_shareView removeFromSuperview];

    

    [self.indicator startAnimating];

}


//退出登陆回调方法

- (void) exitShare:(UIButton*) sender

{

    SinaWeibo *sinaWeibo = [self sinaWeibo];

    

    [sinaWeibo logOut];

    

    [_shareView removeFromSuperview];

    

    NSLog(@"退出登陆");

}


//请求完成回调该方法

- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result

{

    [self.indicator stopAnimating];

    

    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"发送成功" message:@"提示"delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

    [alert show];

    [alert release];

    NSLog(@"发送成功");

}


//请求失败回调该方法

- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error

{

    [self.indicator stopAnimating];

    

    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"发送失败,请检测网络链接" message:@"提示"delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

    [alert show];

    [alert release];

    NSLog(@"发送失败");

}



- (void)viewDidUnload

{

    [super viewDidUnload];

    // Release any retained subviews of the main view.

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}


@end

效果你也可以去http://code4app.com/ios/SinaWeibo-Share/50d973306803fad965000000 现在dome 去参考一下!我就是在此参考的!



个人信息获得 

@interface UserInfoViewController : UIViewController<SinaWeiboRequestDelegate>//实现请求代理

BOOL authValid = self.sina.isAuthValid;//判断是否授权了

    if (authValid){

        [self.sina requestWithURL:@"users/show.json" params:[NSMutableDictionarydictionaryWithObject:self.sina.userID forKey:@"uid"httpMethod:@"GET" delegate:self];

    }

//请求失败回调方法

- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error{

    if ([request.url hasSuffix:@"users/show.json"]){

        [self.userInfoDic release], self.userInfoDic nil;

    }

}


//请求成功回调方法

- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result{

    if ([request.url hasSuffix:@"users/show.json"]){

        [self.userInfoDic release];

        self.userInfoDic = [result retain];

        //NSLog(@"用户信息字典:%@", self.userInfoDic); 字典数据 返回字段下面

    }

 

}

返回字段说明

返回值字段 字段类型 字段说明
id int64 用户UID
idstr string 字符串型的用户UID
screen_name string 用户昵称
name string 友好显示名称
province int 用户所在省级ID
city int 用户所在城市ID
location string 用户所在地
description string 用户个人描述
url string 用户博客地址
profile_image_url string 用户头像地址,50×50像素
profile_url string 用户的微博统一URL地址
domain string 用户的个性化域名
weihao string 用户的微号
gender string 性别,m:男、f:女、n:未知
followers_count int 粉丝数
friends_count int 关注数
statuses_count int 微博数
favourites_count int 收藏数
created_at string 用户创建(注册)时间
following boolean 暂未支持
allow_all_act_msg boolean 是否允许所有人给我发私信,true:是,false:否
geo_enabled boolean 是否允许标识用户的地理位置,true:是,false:否
verified boolean 是否是微博认证用户,即加V用户,true:是,false:否
verified_type int 暂未支持
remark string 用户备注信息,只有在查询用户关系时才返回此字段
status object 用户的最近一条微博信息字段 详细
allow_all_comment boolean 是否允许所有人对我的微博进行评论,true:是,false:否
avatar_large string 用户大头像地址
verified_reason string 认证原因
follow_me boolean 该用户是否关注当前登录用户,true:是,false:否
online_status int 用户的在线状态,0:不在线、1:在线
bi_followers_count int 用户的互粉数
lang string 用户当前的语言版本,zh-cn:简体中文,zh-tw:繁体中文,en:英语

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值