Routine
1. Create App http://open.weibo.com/apps/3989606836/info/advanced
2. Get information about the app and view the Weibo API
3, http://open.weibo.com/wiki/Oauth2/authorize OAuth2 authorize interface,
4. Http://open.weibo.com/wiki/OAuth2/access_token Get Access_token
6, you can use Access_token, as the parameters of the network request for Weibo
Related code
#import <UIKit/UIKit.h>@interface iwoauthviewcontroller:uiviewcontroller@ End
#import "IWOAuthViewController.h"#import "mbprogresshud+mj.h"#import "AFNetworking.h"#import "MJExtension.h"#import "IWAccount.h"#import "IWAccountTool.h"#import "HomeViewController.h"@interfaceIwoauthviewcontroller () <UIWebViewDelegate>@end@implementationIwoauthviewcontroller- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.UIWebView*webview =[[UIWebView alloc] init]; Webview.frame=Self.view.bounds; WebView.Delegate=Self ; [Self.view Addsubview:webview]; Self.view.backgroundColor=[Uicolor Orangecolor]; //piersnovia;3989606836;0300642b574cdcd130f008bf3500f20b;http://www.baidu.com //loading the page, where loading fails, you need to modify the Plist fileNsurl *url = [Nsurl urlwithstring:@ "https://api.weibo.com/oauth2/authorize?client_id=3989606836&redirect_ Uri=http://www.baidu.com "]; Nsurlrequest*requset =[Nsurlrequest Requestwithurl:url]; [WebView Loadrequest:requset];}#pragmaMark-webview callback Method-(void) Webviewdidstartload: (UIWebView *) webview{//Show Reminder Box[Mbprogresshud ShowMessage:@"Brother is helping you to load the ..."];}- (void) Webviewdidfinishload: (UIWebView *) webview{//Hide Reminder Box[Mbprogresshud Hidehud];}- (void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nserror *) error{//Hide Reminder Box[Mbprogresshud Hidehud];}-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (uiwebviewnavigationtype) navigationtype{//each time a request is returned to the network, we have to get a codeNSString *urlstr =request. url.absolutestring; //should start = =HTTP://WWW.BAIDU.COM/?CODE=9D3115D76EB1AB915F391514CEB20DBDNsrange range = [Urlstr rangeofstring:@"code="]; if(range.length) {//0. Get the codeNSString *code = [Urlstr substringfromindex:range.location+Range.length]; //1. Create a request Management ObjectAfhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager Manager]; //2. Package Request ParametersNsmutabledictionary *params=[Nsmutabledictionary dictionary]; params[@"client_id"] =@"3989606836"; params[@"Client_secret"] =@"0300642b574cdcd130f008bf3500f20b"; params[@"Grant_type"] =@"Authorization_code"; params[@"Code"] =Code; params[@"Redirect_uri"] =@"http://www.baidu.com"; //3. Sending the request[Mgr post:@ "Https://api.weibo.com/oauth2/access_token" Parameters:paramsSuccess:^ (Afhttprequestoperation *operation,IDresponseobject) { //Parse file formation modelIwaccount *account =[Iwaccount Objectwithkeyvalues:responseobject]; //Storage Model[Iwaccounttool Saveaccount:account]; //Jump[Self Presentviewcontroller:[homeviewcontrollerNew] Animated:yes Completion:nil]; [Mbprogresshud Hidehud]; } Failure:^ (Afhttprequestoperation *operation, Nserror *error) { //Hide Reminder Box[Mbprogresshud Hidehud]; }]; [Mbprogresshud Hidehud]; } returnYES;}
Access to Weibo data