如何在ios5.0 iphone中查找twitter的用户名和密钥
嗨,我成功地将twitter与ios5.0整合到我的iphone应用程序中。如何在ios5.0 iphone中查找twitter的用户名和密钥,iphone,ios5,twitter,Iphone,Ios5,Twitter,嗨,我成功地将twitter与ios5.0整合到我的iphone应用程序中。 我的问题是,我在ios 5.0中使用两个帐户登录twitter,然后从我的应用程序中获取tweet,如何知道哪个用户发了tweet或活动帐户的用户id使用此方法获取用户信息 - (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username { NSUserDefaults *defaults
我的问题是,我在ios 5.0中使用两个帐户登录twitter,然后从我的应用程序中获取tweet,如何知道哪个用户发了tweet或活动帐户的用户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);
}
我们将在
tweetcomposeviewcontroller中获取用户名。您可以获得如图所示的选择器,并从中选择一个帐户
当你直接发推特时,在account的帮助下,你可以通过
+ (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];
+(void)pritnUserName{
//创建帐户存储对象。
ACAccountStore*accountStore=[[ACAccountStore alloc]init];
//创建确保检索Twitter帐户的帐户类型。
ACAccountType*accountType=[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierWitter];
//请求用户访问以使用其Twitter帐户。
[accountStore requestAccessToAccountsWithType:accountType with CompletionHandler:^(已授予布尔,N错误*错误){
如果(授予){
//获取Twitter帐户列表。
NSArray*accountsArray=[accountStore accountsWithAccountType:accountType];
//为了简洁起见,我们假设只有一个Twitter帐户。
//如果存在多个Twitter帐户,您最好询问用户希望从哪个帐户发送推文。
如果([accountsArray count]>0){
//抓取最初的推特帐户,从中推特。
对于(int i=0;i<[accountsArray count];i++){
ACAccount*twitterAccount=[accountsArray对象索引:i];
NSLog(@“用户名:%d是%@”,i+1,twitterAccount.username);
}
}
}
}];
[accountStore发布];
}