1
这是Sam.Currently我devloping twitter份额在我的应用程序。我需要实现,没有ComposeController.I需要与社会框架SLRequest集成。 这是我使用的代码是如下的Twitter与SLRequest共享
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Creating Request");
// Step 2: Create a request
NSArray *twitterAccounts =[accountStore accountsWithAccountType:twitterAccountType];
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.0/statuses/update.json"];
NSDictionary *params = @{@"screen_name" : @"naheshsamy",@"include_rts" : @"0",@"trim_user" : @"1",@"count" : @"1"};
SLRequest *request =
[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params];
// Attach an account to the request
[request setAccount:[twitterAccounts lastObject]];
NSLog(@"Request %@",request);
// Step 3: Execute the request
[request performRequestWithHandler: ^(NSData *responseData,NSHTTPURLResponse *urlResponse,NSError *error) {
if (responseData) {
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSError *jsonError;
NSDictionary *timelineData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&jsonError];
if (timelineData) {
NSLog(@"Timeline Response: %@\n", timelineData);
}
else {
// Our JSON deserialization went awry
NSLog(@"JSON Error: %@", [jsonError localizedDescription]);
}
}
else {
// The server did not respond ... were we rate-limited?
NSLog(@"The response status code is %d %@ %@",urlResponse.statusCode,urlResponse.suggestedFilename,error);
}
}
}];
}
else {
// Access was not granted, or an error occurred
NSLog(@"%@", [error localizedDescription]);
}
}];
我一直在获取状态400错误.. 任何帮助将不胜感激。 Regards, Sam.P
感谢您的宝贵答案里拉..现在我已经与twitter API's成功分享。现在我需要知道如何与访问令牌共享没有使用默认的Twitter帐户.. – MaheThiru 2014-09-08 03:15:26