0

嗨,我已成功将 twitter 与 ios5.0 集成到我的 iphone 应用程序中。我的问题是我在 ios 5.0 的 twitter 中使用两个帐户登录,然后对于来自我的应用程序的推文,我如何知道哪个用户发了推文或活动帐户的用户 ID

4

2 回答 2

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];

}

于 2012-07-06T11:38:53.770 回答
0

使用此方法获取用户信息

- (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);
}

我们将在这里获取用户名

于 2012-06-22T07:16:50.387 回答