繁体   English   中英

如何在iOS5.0 iPhone中找到Twitter中的用户名和密钥

[英]how to find username and key in twitter in ios5.0 iphone

嗨,我已经成功将Twitter与ios5.0集成到了我的iPhone应用程序中。 我的问题是我在ios 5.0中用Twitter中的两个帐户登录,然后从我的应用程序发送了推文,我如何知道哪个用户发了推特或有效帐户的用户ID

使用此方法获取用户信息

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

我们将在此处获取用户名

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM