Github:https://github.com/hellovoidworld/hvwweibo A. Use the Weibo API to send Weibo 1. Demand learning Send Weibo API send text Weibo send Weibo with pictures 2. Ideas directly follow the instructions in the Weibo API's documentation Test upload here with picture Weibo3. ImplementOn the "tweet" screen, click Send in the top right corner to call the API
1 //HVWCOMPOSEVIEWCONTROLLER.M2 /** 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 micro-blog ..."];Ten One if(Self.imageDisplayView.images.count) {//send a tweet with a picture A [self sendweibowithtextnimage]; -}Else{//send a text-only Weibo - [self sendweibowithtext]; the } - } - - /** Send text Weibo*/ +- (void) Sendweibowithtext { - //Create an HTTP operations Manager +Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager]; A at //Setting Parameters -Nsmutabledictionary *param =[Nsmutabledictionary dictionary]; - //Access Tokens -Hvwaccountinfo *accountinfo =[Hvwaccountinfotool AccountInfo]; -param[@"Access_token"] =Accountinfo.access_token; - //Weibo text inparam[@"Status"] =Self.composeView.text; - to //Send Request +[Manager POST:@"Https://api.weibo.com/2/statuses/update.json"Parameters:param success:^ (Afhttprequestoperation *operation,IDresponseobject) { - [Mbprogresshud Hidehud]; the[Mbprogresshud showsuccess:@"sent successfully!"]; *} failure:^ (Afhttprequestoperation *operation, Nserror *error) { $Hvwlog (@"failed to send Weibo, error:%@", error);Panax Notoginseng [Mbprogresshud Hidehud]; -[Mbprogresshud ShowError:@"Send failed!error"]; the }]; + } A the /** Send pictures and tweets*/ +- (void) Sendweibowithtextnimage { - if(Self.imageDisplayView.images.count = =0) { $ [Mbprogresshud Hidehud]; $[Mbprogresshud ShowError:@"Meng, can not find the picture Son!"]; - return; - } the - //Create an HTTP operations ManagerWuyiAfhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager]; the - //Setting Parameters WuNsmutabledictionary *param =[Nsmutabledictionary dictionary]; - //Access Tokens AboutHvwaccountinfo *accountinfo =[Hvwaccountinfotool AccountInfo]; $param[@"Access_token"] =Accountinfo.access_token; - //Weibo text -param[@"Status"] =Self.composeView.text; - A //Send Request +[Manager POST:@"Https://upload.api.weibo.com/2/statuses/upload.json"Parameters:param constructingbodywithblock:^ (ID<AFMultipartFormData>formData) { the - //send the picture data, in fact now open API only allow to upload a picture $UIImage *image =[Self.imageDisplayView.images Firstobject]; the if(image) { theNSData *imagedata =uiimagepngrepresentation (image); the[FormData appendpartwithfiledata:imagedata Name:@"pic"FileName:@"Statuspic"MimeType:@"Image/png"]; the } -} success:^ (Afhttprequestoperation *operation,IDresponseobject) { in [Mbprogresshud Hidehud]; the[Mbprogresshud showsuccess:@"sent successfully!"]; the} failure:^ (Afhttprequestoperation *operation, Nserror *error) { AboutHvwlog (@"failed to send Weibo, error:%@", error); the [Mbprogresshud Hidehud]; the[Mbprogresshud ShowError:@"Send failed!"]; the }]; +}
Send success:#mark:The reasons for the failure to send Weibo are: 1. No text content 2. Use the Send plain text API, but upload a picture 3. Using the Send graphics API, but not uploading pictures note: Sina's Open API can only upload one image at a time, the last one will be used when selecting multiple images.
[iOS Weibo project-3.2]-send Weibo