iPhone程序中将内容分享到新浪微博

本文介绍了如何在iPhone应用程序中实现用户登录验证及内容(包括图片和文字)分享到新浪微博的功能。首先,需要在新浪开放平台注册应用获取App Key,然后通过基本授权方式完成登录验证。如果验证成功,使用 multipart/form-data 格式构造请求体,将内容上传到新浪微博API,以完成分享操作。
摘要由CSDN通过智能技术生成

因为要用到,所以找来,和大家分享:

1. 首先在http://open.t.sina.com.cn/中申请成为开发者,再创建不同的应用,获得相应的App Key (在下面链接中的source即为app key)

 

2. 登录认证:

NSString *authString = [NSString stringWithFormat:@"%@:%@",sinaIDField.text,sinaPasswordField.text];

NSData *authData = [authString dataUsingEncoding:NSUTF8StringEncoding];

NSString *authValue = [NSString stringWithFormat:@"Basic %@",[authData base64EncodingWithLineLength:80]];

 

NSURL *url = [NSURL URLWithString:@"http://api.t.sina.com.cn/account/verify_credentials.xml?source=3930264715"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

[request setHTTPMethod:@"GET"];

[request setValue:authValue forHTTPHeaderField:@"Authorization"];

 

NSURLResponse *response;

NSError *error;

 

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

 

[request release];

 

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

 

int statusCode = [httpResponse statusCode];

 

NSLog(@"status code = %d",statusCode);

 

if (statusCode != 200) {

alertTitle = @"帐号或密码错误";

alertMassage = @"请您输入正确的帐号和密码!";

}else {

alertTitle = @"";

alertMassage = @"登录成功!";

}

}

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle

message:alertMassage

delegate:nil can

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值