Access to Weibo data

Source: Internet
Author: User

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

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.