Ios 如何获取使用twitter SLRequest登录的用户信息?

Ios 如何获取使用twitter SLRequest登录的用户信息?,ios,twitter,slrequest,Ios,Twitter,Slrequest,我想在twitter中使用SLRequest获取用户配置文件信息 目前我正在像这样编码 NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"]; NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"ali",@"screen_name",nil]; account = [[ACAcco

我想在twitter中使用SLRequest获取用户配置文件信息

目前我正在像这样编码

  NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"];
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"ali",@"screen_name",nil];

    account = [[ACAccountStore alloc] init];
    ACAccountType *twitterAccountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    NSArray *twitterAccounts = [account accountsWithAccountType:twitterAccountType];

    // Runing on iOS 6
    if ([LoginViewController isTwitterAvailable])
    {
        NSLog(@"In the IFF...... ");
        [account requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error)
         {
             NSLog(@"in body ");

             if (granted)
             {
                 NSLog(@"in granted ..");


                 SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params];

                 [request setAccount:[twitterAccounts lastObject]];

                 dispatch_async(dispatch_get_main_queue(), ^
                                {

                                    [NSURLConnection sendAsynchronousRequest:request.preparedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)
                                     {
                                         dispatch_async(dispatch_get_main_queue(), ^
                                                        {
                                                            if (data)
                                                            {
                                                                //NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ;


                                                                //NSLog(@"data:%@",string);

                                                                NSError* error;


                                                                NSDictionary* dicUser = [NSJSONSerialization
                                                                                      JSONObjectWithData:data

                                                                                      options:kNilOptions 
                                                                                      error:&error];
它返回整个信息,而不是配置文件信息

如何获取正在登录的用户的配置文件信息


谢谢

请尝试从一个live项目中提供以下代码,您可以根据现有结构进行修改。如果有任何问题,请告诉我

  _accountStore = [[ACAccountStore alloc] init]; //Declare accountStore as property and initialize
  ACAccountType *accountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    [_accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
        if (granted){
            NSArray *accounts = [_accountStore accountsWithAccountType:accountType];
            if (accounts.count > 0){
                ACAccount *twitterAccount = [accounts lastObject];
                NSDictionary *dict1 = [twitterAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]];
                NSDictionary *properties = dict1[@"properties"];
                NSDictionary *returnDict = @{@"TwitterID":properties[@"user_id"],@"UserName":twitterAccount.username};
                NSLog(@"Profile details->%@",properties);
            }else{
                NSMutableDictionary* details = [NSMutableDictionary dictionary];
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
                error = [NSError errorWithDomain:@"Domain" code:error.code userInfo:details];
                NSLog(@"Error occured->%@",error.localizedDescription);
            }
        } else {
            NSMutableDictionary* details = [NSMutableDictionary dictionary];
            if(error.code == ACErrorAccountNotFound){
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
            }else if(error.code == ACErrorPermissionDenied || error.code == ACErrorAccessDeniedByProtectionPolicy) {
                [details setValue:kTwitterAccessDeniedMsg forKey:NSLocalizedDescriptionKey];
            }else {
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
            }
            error = [NSError errorWithDomain:@"Domain" code:error.code userInfo:details];
            NSLog(@"Error occured->%@",error.localizedDescription);
        }
    }];
很少有宏

#define kTwitterErrorMsg                @"Please set your Twitter account in Settings."
#define kTwitterAccessDeniedMsg         @"Twitter Access denied."

尝试从一个实时项目中提供以下代码,您可以根据现有结构进行修改。如果有任何问题,请告诉我

  _accountStore = [[ACAccountStore alloc] init]; //Declare accountStore as property and initialize
  ACAccountType *accountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    [_accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
        if (granted){
            NSArray *accounts = [_accountStore accountsWithAccountType:accountType];
            if (accounts.count > 0){
                ACAccount *twitterAccount = [accounts lastObject];
                NSDictionary *dict1 = [twitterAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]];
                NSDictionary *properties = dict1[@"properties"];
                NSDictionary *returnDict = @{@"TwitterID":properties[@"user_id"],@"UserName":twitterAccount.username};
                NSLog(@"Profile details->%@",properties);
            }else{
                NSMutableDictionary* details = [NSMutableDictionary dictionary];
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
                error = [NSError errorWithDomain:@"Domain" code:error.code userInfo:details];
                NSLog(@"Error occured->%@",error.localizedDescription);
            }
        } else {
            NSMutableDictionary* details = [NSMutableDictionary dictionary];
            if(error.code == ACErrorAccountNotFound){
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
            }else if(error.code == ACErrorPermissionDenied || error.code == ACErrorAccessDeniedByProtectionPolicy) {
                [details setValue:kTwitterAccessDeniedMsg forKey:NSLocalizedDescriptionKey];
            }else {
                [details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
            }
            error = [NSError errorWithDomain:@"Domain" code:error.code userInfo:details];
            NSLog(@"Error occured->%@",error.localizedDescription);
        }
    }];
很少有宏

#define kTwitterErrorMsg                @"Please set your Twitter account in Settings."
#define kTwitterAccessDeniedMsg         @"Twitter Access denied."

谢谢,我有用户名,ID,但是关于电子邮件和性别我可以访问什么值呢?不管允许什么,你都可以在字典里找到。只需打印dict1并检查什么是comingproperties={“user_id”=292793696;};这里只有一个属性?尝试打印twitterAccount本身,看看会发生什么。现在无法检查,请尝试打印twitterAccount的说明,但它只显示用户id。请帮助我@Janak Nirmal。谢谢,我有用户名、id,但关于电子邮件和性别,我可以访问哪些值?无论允许什么,你都将在该字典中获得。只需打印dict1并检查什么是comingproperties={“user_id”=292793696;};这里只有一个属性?尝试打印twitterAccount本身,看看会发生什么。现在无法检查,所以请尝试打印Twitter帐户的说明,但它只显示用户id。请帮助我@Janak Nirmal。