Search code examples
emailtwittertwitter-fabric

Objective C retrieve twitter email from JSON


TwitterKit changed the way its email gets retrieved again and now I can't figure out how to retrieve the email from JSON using the new format.

Previously I would just do this:

TWTRShareEmailViewController* shareEmailViewController =
             [[TWTRShareEmailViewController alloc]
              initWithCompletion:^(NSString* email2, NSError* error) {
                  NSLog(@"Email %@, Error: %@", email2, error);

But now they've gotten rid of the TWTRShareEmailViewController (as of version 2.0) and I have to do this:

TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
             NSURLRequest *request = [client URLRequestWithMethod:@"GET"
                                                              URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"
                                                       parameters:@{@"include_email": @"true", @"skip_status": @"true"}
                                                            error:nil];

             [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
**something should go here**
 }];

...but I'm not quite sure how to get the email from the json now.

Any help would be appreciated.


Solution

  • Ok. In the end it was pretty easy. All I had to do was convert the JSON to a string. And from there I could do whatever I wanted to it. So I did it this way:

    TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
                 NSURLRequest *request = [client URLRequestWithMethod:@"GET"
                                                                  URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"
                                                           parameters:@{@"include_email": @"true", @"skip_status": @"true"}
                                                                error:nil];
    
                 [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
     }];
    

    From there you could turn it to a dictionary or array or whatever you want to do with it. Phew! I really need more sleep!