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.
Get App key and App Secret after application
2. Download ios_sdk
Download the first one.
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 api for sending Weibo messages is: statuses/upload to send Weibo messages 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 longitude of the east 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.
[Cpp]
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.
In this way, you can obtain the nickname of your Weibo account.
The methods and examples used are as follows.
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.