【问题标题】:Twitter.framework issueTwitter.framework 问题
【发布时间】:2012-06-22 07:38:34
【问题描述】:

我正在使用 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”。这意味着成功!来自twitter site。 但是我不明白,如果我什至不输入任何登录名和密码,它怎么能成功。我应该在哪里设置登录名和密码?

【问题讨论】:

    标签: iphone image twitter twrequest


    【解决方案1】:

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

    【讨论】:

    • 是的,帐户详细信息正在从设备设置传递到您执行此操作时发送到服务器的请求:[postRequest setAccount:twitterAccount];
    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2012-02-19
    • 2013-12-04
    • 2012-01-28
    • 2013-09-17
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多