Last active
August 29, 2015 14:10
-
-
Save lepture/14e41751f777ec9bc5e4 to your computer and use it in GitHub Desktop.
test weibo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import Social; | |
@import Accounts; | |
- (void)testWeibo { | |
BOOL isWeiboAvailable = [SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]; | |
NSLog(@"isWeiboAvailable:%d", isWeiboAvailable); | |
if (isWeiboAvailable) { | |
ACAccountStore *accountStore = [[ACAccountStore alloc] init]; | |
ACAccountType *weiboAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo]; | |
[accountStore requestAccessToAccountsWithType:weiboAccountType options:nil completion:^(BOOL granted, NSError *error) { | |
if (granted) { | |
NSLog(@"granted!!"); | |
NSArray *weiboAccounts = [accountStore accountsWithAccountType:weiboAccountType]; | |
NSLog(@"weiboAccounts:%@", weiboAccounts); | |
NSURL *url = [NSURL URLWithString:@"https://api.weibo.com/2/statuses/user_timeline.json"]; | |
NSDictionary *params = @{@"uid" : @"1846569133"}; | |
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeSinaWeibo | |
requestMethod:SLRequestMethodGET | |
URL:url | |
parameters:params]; | |
// Attach an account to the request | |
[request setAccount:[weiboAccounts lastObject]]; | |
// Step 3: Execute the request | |
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { | |
if (responseData) { | |
NSError *jsonError; | |
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:responseData | |
options:NSJSONReadingAllowFragments | |
error:&jsonError]; | |
NSLog(@"%@", jsonData); | |
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) { | |
NSLog(@"success"); | |
} else { | |
NSLog(@"%ld", (long)urlResponse.statusCode); | |
} | |
} else { | |
NSLog(@"No data"); | |
} | |
}]; | |
} else { | |
NSLog(@"not granted!!"); | |
} | |
}]; | |
} else { | |
NSLog(@"no account"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment