English 中文(简体)
我如何接触用户 方框5中“Twitter”框架的简介信息?
原标题:How can I get the users Twitter profile information with the Twitter framework in iOS 5?

我可以把以下守则张贴到Twitter上:

TWTweetComposeViewController *tweeter = [[TWTweetComposeViewController alloc] init];
        [tweeter setInitialText:@"message"];
        [tweeter addImage:image];
        [self presentModalViewController:tweeter animated:YES];

我如何接触用户 方框5中“Twitter”框架的简介信息?

问题回答

顺便说一句,你想在一张桌上显示用户在其装置上的垂直账户。 你很可能想在桌子上显示瓦tar,在这种情况下,你需要询问Twitter的图像。

假设您的密码>,>ACAccount物体,您可设立一个词典,为每个账户储存额外信息。 页: 1 我们需要这样的一些法典:

    // Assuming that you ve dequeued/created a UITableViewCell...

    // Check to see if we have the profile image of this account
    UIImage *profileImage = nil;
    NSDictionary *info = [self.twitterProfileInfos objectForKey:account.identifier];
    if (info) profileImage = [info objectForKey:kTwitterProfileImageKey];

    if (profileImage) {
        // You ll probably want some neat code to round the corners of the UIImageView
        // for the top/bottom cells of a grouped style `UITableView`.
        cell.imageView.image = profileImage;

    } else {
        [self getTwitterProfileImageForAccount:account completion:^ {
            // Reload this row
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }];            
    }

All this is doing is accessing a UIImage object from a dictionary of dictionaries, keyed by the account identifier and then a static NSString key. If it doesn t get an image object, then it calls an instance method, passing in a completion handler block, which reloads the table row. The instance methods looks a bit like this:

#pragma mark - Twitter

- (void)getTwitterProfileImageForAccount:(ACAccount *)account completion:(void(^)(void))completion {

    // Create the URL
    NSURL *url = [NSURL URLWithString:@"users/profile_image" relativeToURL:kTwitterApiRootURL];

    // Create the parameters
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            account.username, @"screen_name", 
                            @"bigger", @"size",
                            nil];

    // Create a TWRequest to get the the user s profile image
    TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];

    // Execute the request
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

        // Handle any errors properly, not like this!        
        if (!responseData && error) {
            abort();
        }

        // We should now have some image data
        UIImage *profileImg = [UIImage imageWithData:responseData];

        // Get or create an info dictionary for this account if one doesn t already exist
        NSMutableDictionary *info = [self.twitterProfileInfos objectForKey:account.identifier];
        if (!info) {
            info = [NSMutableDictionary dictionary];            
            [self.twitterProfileInfos setObject:info forKey:account.identifier];
        }

        // Set the image in the profile
        [info setObject:profileImg forKey:kTwitterProfileImageKey];

        // Execute our own completion handler
        if (completion) dispatch_async(dispatch_get_main_queue(), completion);
    }];
}

因此,确保你不屈不.,但随后在下载简介图像时将更新表格。 在你完成学业时,你可以把他们放在形象的十字架上,否则就将他们延续到阶级的寿命之后。

也可使用同样的程序获取其他“Twitter”用户信息:

上述方法正在克服重复问题。 简单使用:

ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSLog(twitterAccount.accountDescription);




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签