The Sina Weibo open platform provides a simple cooperation model for third-party applications, meeting the needs of mobile phone users and tablet users to share information anytime, anywhere. You can call the platform api to implement many functions on Weibo.
This article mainly aims to record the iOS version of Sina Weibo mobile SDK embedded and used under iOS5.
1. Apply for a mobile app on Sina Weibo.
Application address: http://open.weibo.com/development. after the application is completed, the App key and App Secret are obtained.
2. Download iOS_sdk
: Http://open.weibo.com/wiki/SDK#iOS_SDK, download the first one on OK.
3. Create a project Sina_weibo and select single View app. In addition, the ARC feature after 5.0 is used. Import the decompressed sdk
Import SDK
4. compatible SDK running in the arc environment
When you run the program, you will find many errors about the ARC, because the sdk does not use the arc. In this case, if you want the sdk file not to participate in the compilation of the arc method, you need to make the following settings and add the "-fno-objc-arc" mark in Build Phases.
Double-click the file to be identified and enter-fno-objc-arc.
In this way, the files of the weibo SDK will not be compiled in the arc method.
5. Add Security. framework in your project. The SDK needs to use Security. framework to put the token after OAuth authentication into the keyChain to increase the Security of the entire project.
At this time, the program will compile and run normally.
6. other demos are the same as those in the SDK.
Login call
[WeiBoEngine logIn];
Cancel call
[WeiBoEngine logOut];
Weibo:
You can call the SDK's default Interface to send messages:
WBSendView * sendView = [[WBSendView alloc] initWithAppKey: appKey appSecret: appSecret text: @ "test" image: [UIImage imageNamed: @ "bg.png"];
[SendView setDelegate: self];
[SendView show: YES];
The corresponding Weibo sending api is: Statuses / Upload Send Weibo posts and upload images. If the map is displayed on Weibo, send the longitude and latitude parameters, and add more
Lat |
False |
Float |
Latitude. Valid range:-90.0 to + 90.0. + indicates north latitude. The default value is 0.0. |
Long |
False |
Float |
Longitude, valid range:-180.0 to + 180.0, + indicates the eastern longitude. The default value is 0.0. |
7. Call custom APIs
In step 6, the sdk is encapsulated. How can I call such APIs and functions on Weibo?
We tried to get personal information.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:2]; [params setObject:[engine accessToken]forKey:@"access_token"]; [params setObject:[engine userID]forKey:@"uid"]; NSLog(@"params:%@", params); [engine loadRequestWithMethodName:@"users/show.json" httpMethod:@"GET" params:params postDataType:kWBRequestPostDataTypeNone httpHeaderFields:nil];
Params parameters are required.
Returned Data Reference interface http://open.weibo.com/wiki/2/users/show
In this way, you can obtain the nickname of your Weibo account.
All Weibo api documents are posted on this page.
Change loadRequestWithMethodName to the required interface, and change the params parameter to the required parameter.
Some interfaces do not require params, such
Statuses/friends_timeline.json to get the Weibo of the followers. Here params can be nil.
PS: This record uses Oauth. xauth must be qualified for use.
8. Source Code: http://download.csdn.net/detail/totogo2010/4633077
Copyright Disclaimer: This article will be published at http://blog.csdn.net/totogo2010/, and you will be welcomed to enjoy the transfer and sharing. Please respect the work of the author. Keep this note and the author's blog link when reprinting. Thank you!