您好我已经在ios5.0的iphone应用程序中成功集成了twitter。 我的问题是我在ios 5.0中使用Twitter登录了两个帐户然后从我的应用程序发送推文我如何知道哪个用户推文或活动帐户的用户ID
答案 0 :(得分:0)
使用此方法获取userinfo
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: @"authData"];
[defaults synchronize];
}
- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username
{
return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}
以及
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
{
NSLog(@"User Info Received: %@", userInfo);
}
我们将在此处获取用户名
答案 1 :(得分:0)
在TWTweetComposeViewController
您可以获得图片中显示的选择器,您可以从中选择一个帐户。
当您直接发推文时,在ACAccount的帮助下,您可以通过
获取+ (void)pritnUserName {
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
for (int i = 0 ; i < [accountsArray count] ;i++){
ACAccount *twitterAccount = [accountsArray objectAtIndex:i];
NSLog(@"username :%d is %@",i+1,twitterAccount.username);
}
}
}
}];
[accountStore release];
}