图像使用SLRequest和帐户框架在Twitter中发布

时间:2014-10-17 08:55:13

标签: ios ios7 twitter

使用iOS中的SLRequest在Twitter Time Line中发布图像时出现<400>错误。请解决这个问题

ACAccountStore *account=[[ACAccountStore alloc]init];
    ACAccountType *accountType=[account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    img=[UIImage imageNamed:@"ProfilePic"];

    [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        if (granted==YES) {
            NSArray *arrayOfAccount=[account accountsWithAccountType:accountType];
            if ([arrayOfAccount count]>0) {
                ACAccount *twitterAccount=[arrayOfAccount lastObject];


                NSDictionary *parameters=@{@"status": @"Hi"};

                NSURL *request=[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];

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


                NSData *imageData =(NSData*)[UIImage imageNamed:@"ProfilePic"];
                [postRequest addMultipartData:imageData
                                 withName:@"media[]"
                                     type:@"image/jpeg"
                                 filename:@"image.jpg"];


                [postRequest addMultipartData:imageData withName:@"media" type:@"image/jpg" filename:@"image.jpg"];

                postRequest.account=twitterAccount;
                NSLog(@"Post data :%@",postRequest);

                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSLog(@"Twitter HTTP response: %i", [urlResponse
                                                         statusCode]);


                }
                 ];

            }
        }
    }];

0 个答案:

没有答案