iOS 微博 OAuth2.0 分享 文字 + 图片 微博的方法

本文介绍了一种通过iOS SDK实现向新浪微博平台上传图片的方法,并记录了具体的代码实现过程。此外,还提供了几个参考资料链接,以便进一步研究。

也是采用两种方法,先放出第一种方法

 //https://upload.api.weibo.com/2/statuses/upload.json

    //https://api.weibo.com/2/statuses/update.json

    

    NSUserDefaults *info = [NSUserDefaultsstandardUserDefaults];

    NSData *imageData = UIImagePNGRepresentation([UIImageimageNamed:@"auth_header.png"]);

    NSURL *url = [[NSURLalloc] initWithString:@"https://upload.api.weibo.com/2/statuses/upload.json"];

    ASIFormDataRequest *request = [[ASIFormDataRequestalloc] initWithURL:url];

    

    [request addPostValue:SINAAPPKEY forKey:@"source"];

    [request addPostValue:@"sina pic test"forKey:@"status"];

    [request setData:imageData withFileName:@"auth_header.png"andContentType:@"image/jpeg"forKey:@"pic"];

    [request addPostValue:@"0" forKey:@"lat"];

    [request addPostValue:@"0" forKey:@"long"];

    [request addPostValue:[selfDecrypt:PasswordKey :[info objectForKey:@"sina_access_token"]] forKey:@"access_token"];

    [request startSynchronous];

    NSString *resultString = [request responseString];

    NSDictionary *result = [resultString objectFromJSONString];

    NSLog(@"The dic is %@", result);

    

    [request release];

    [url release];

 

使用iOS SDK的方式没有成功,贴几个相关的链接,如果后面有需要再参考

http://aitracy.iteye.com/blog/785402

http://stackoverflow.com/questions/9460817/form-data-request-using-nsurlconnection-in-ios

http://www.oschina.net/code/snippet_12_8203 

 

 

转载于:https://www.cnblogs.com/worldworld/archive/2012/08/10/2632302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值