0

我正在使用 Twitter.framework 将图像发布到 Twitter。我使用此代码

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


                if ([accountsArray count] > 0) {
                    // Grab the initial Twitter account to tweet from.
                    ACAccount *twitterAccount = [accountsArray objectAtIndex:0];



                    UIImage *image =[UIImage imageNamed:@"logo"];


                    TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] 
                                                                 parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST];

                    // "http://api.twitter.com/1/statuses/update.json" 

                    [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];


                    // Set the account used to post the tweet.
                    [postRequest setAccount:twitterAccount];

                    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                        NSLog(@"output = %@\n\n", output);
                    }];
                }
            }
        }];

在日志中,我看到“HTTP 响应状态:200”。这意味着成功!来自推特网站。但我不明白,如果我什至不输入任何登录名和密码,它怎么能成功。我应该在哪里设置登录名和密码?

4

1 回答 1

3

您在“设置”应用中进行身份验证。我假设它使用 xAuth,因此您的应用无需知道用户名和密码。

于 2012-06-20T08:18:46.017 回答