原始地址:IOS 6社交應用開發-新浪微博
1.添加Framework.
2.匯入標頭檔.
#import <Accounts/Accounts.h>#import <Social/Social.h>
3.確保在“設定”裡配置了社交應用的帳戶(以新浪微博舉例),如。
4.擷取新浪微博使用者.
//擷取帳號儲存 ACAccountStore *strore = [[ACAccountStore alloc] init]; //擷取新浪微博的帳號類型 ACAccountType *type = [strore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo]; //驗證是否配置了匹配帳戶 [strore requestAccessToAccountsWithType:type options:nil completion:^(BOOL granted, NSError *error) { if (granted)//驗證授權成功 { //擷取新浪微博使用者列表 NSArray *counts = [strore accountsWithAccountType:type]; if (counts && [counts count] > 0) { //認證通過 //以第一個使用者舉例 [self requestWithAccount:[counts objectAtIndex:0]]; } } }];
5.發布微博.
新浪微博介面文檔
- (void)requestWithAccount:(ACAccount *)account{ /* //類型 SLServiceTypeTwitter SLServiceTypeFacebook SLServiceTypeSinaWeibo //方法 SLRequestMethodGET SLRequestMethodPOST SLRequestMethodDELETE */ //請求地址,參考 NSURL *url = [NSURL URLWithString:@"https://open.weibo.cn/2/statuses/update"]; //配置參數字典 NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:@"ssstext", @"status", nil]; //配置輕取 SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeSinaWeibo requestMethod:SLRequestMethodGET URL:url parameters:para]; //裝載微博使用者 request.account = account; //發送微博 [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (!error) { //主線程中操作UI dispatch_async(dispatch_get_main_queue(), ^{ NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"請求結果:%@",response); //操作UI }); } }];}