您的位置:首页 > 移动开发 > IOS开发

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

2012-08-10 17:43 435 查看
也是采用两种方法,先放出第一种方法

//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的方式没有成功,贴几个相关的链接,如果后面有需要再参考

/content/3384943.html

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

http://www.oschina.net/code/snippet_12_8203
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: