[IOS Weibo project, [iOS blog Project

Source: Internet
Author: User

[IOS Weibo project, [iOS blog Project
Github: https://github.com/hellovoidworld/HVWWeibo. use Weibo API to send Weibo 1. demand learning send Weibo API send text Weibo send Weibo with pictures 2. follow the instructions in the Weibo API documentation to test uploading Weibo images.3. ImplementationOn the Weibo page, click send in the upper-right corner to call the API.

1 // HVWComposeViewController. m 2/** send Weibo */3-(void) sendWeibo {4 if (self. composeView. text. length = 0) {5 [MBProgressHUD showError: @ "You seem to have forgotten the content... "]; 6 return; 7} 8 9 [MBProgressHUD showMessage: @" Send Weibo... "]; 10 11 if (self. imageDisplayView. images. count) {// Weibo 12 [self sendWeiboWithTextNImage]; 13} else {// Weibo 14 [self sendWeiboWithText]; 15} 16} 17 18/** send text Weibo */19-(void) s EndWeiboWithText {20 // create http operation manager 21 AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager]; 22 23 // set parameter 24 NSMutableDictionary * param = [NSMutableDictionary]; 25 // access token 26 HVWAccountInfo * accountInfo = [HVWAccountInfoTool accountInfo]; 27 param [@ "access_token"] = accountInfo. access_token; 28 // Weibo text 29 param [@ "status"] = self. composeView. text; 30 31 // send request 32 [man Ager POST: @ "https://api.weibo.com/2/statuses/update.json" parameters: param success: ^ (AFHTTPRequestOperation * operation, id responseObject) {33 [MBProgressHUD hideHUD]; 34 [MBProgressHUD showSuccess: @ "sent successfully! "]; 35} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {36 HVWLog (@" Weibo failed to send, error: % @ ", error ); 37 [MBProgressHUD hideHUD]; 38 [MBProgressHUD showError: @ "failed to send! Error "]; 39}]; 40} 41 42/** send text Weibo */43-(void) sendWeiboWithTextNImage {44 if (self. imageDisplayView. images. count = 0) {45 [MBProgressHUD hideHUD]; 46 [MBProgressHUD showError: @ "success, no figure found! "]; 47 return; 48} 49 50 // create an http operation manager 51 AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager]; 52 53 // set the parameter 54 NSMutableDictionary * param = [NSMutableDictionary dictionary]; 55 // access token 56 HVWAccountInfo * accountInfo = [HVWAccountInfoTool accountInfo]; 57 param [@ "access_token"] = accountInfo. access_token; 58 // Weibo text 59 param [@ "status"] = self. composeView. text; 60 61 // send request 62 [ma Nager POST: @ "https://upload.api.weibo.com/2/statuses/upload.json" parameters: param constructingBodyWithBlock: ^ (id <AFMultipartFormData> formData) {63 64 // sent image data, in fact, the open API only allows uploading an image 65 UIImage * image = [self. imageDisplayView. images firstObject]; 66 if (image) {67 NSData * imageData = UIImagePNGRepresentation (image); 68 [formData appendPartWithFileData: imageData name: @ "pic" fileName: @ "statusPic" mimeT Ype: @ "image/png"]; 69} 70} success: ^ (AFHTTPRequestOperation * operation, id responseObject) {71 [MBProgressHUD hideHUD]; 72 [MBProgressHUD showSuccess: @ "sent successfully! "]; 73} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {74 HVWLog (@" failed to send Weibo message, error: % @ ", error ); 75 [MBProgressHUD hideHUD]; 76 [MBProgressHUD showError: @ "failed to send! "]; 77}]; 78}

 

Sent successfully: # Mark:Reasons for failed Weibo sending: 1. no text content 2. use the plain text API to upload images. 3. use the send text API, but do not upload images. Note: Sina's open API can only upload one image at a time. When multiple images are selected, the last image is used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.