http - 将用户个人资料图片发布到 Twitter 时出现错误 131

标签 http post twitter ios7

尝试将用户个人资料图片发布到 Twitter 时,我收到错误代码 131 响应:

2013-12-06 19:17:29.854 Tweetly[8131:60b] {
    errors =     (
                {
            code = 131;
            message = "Internal error";
        }
    );
}

Twitter 网站列出了这个:

“对应于 HTTP 500 - 发生了未知的内部错误。”

这是我的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {


    //Code for store image
    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    UIImage *scaledImage = [self imageWithImage:image convertToSize:CGSizeMake(500, 500)];
    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(scaledImage)];

    [self uploadPictureWithData:imageData];

}


- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {

    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return destImage;

}



- (void)uploadPictureWithData:(NSData *)imageData {

    // Get the twitter feed
    NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/account/update_profile_image.json"];

    // Set up proper parameters
    NSMutableDictionary *timelineParameters = [[NSMutableDictionary alloc] init];
    [timelineParameters setObject:imageData forKey:@"image"];
    [timelineParameters setObject:@"1" forKey:@"skip_status"];

    // Create the Social Request
    SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:requestURL parameters:timelineParameters];
    postRequest.account = self.delegate.userAccount;

    // Perform the request
    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            // Check if we reached the reate limit
            if ([urlResponse statusCode] == 429) {

                // Rate limit reached
                // Display an alert letting the user know we have hit the rate limit

                UIAlertView *twitterAlert = [[UIAlertView alloc] initWithTitle:kRateLimitTitle
                                                                       message:kRateLimitMessage
                                                                      delegate:nil
                                                             cancelButtonTitle:@"Ok"
                                                             otherButtonTitles:nil];
                [twitterAlert show];

                return;

            }
            // Check if there was an error
            if (error) {

                NSLog(@"Error: %@", error.localizedDescription);
                return;

            }
            // Check if there is some response data
            if (responseData) {
                NSError *jsonError = nil;
                NSMutableArray *feedData = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
                if (!jsonError) {

                    // Check the response data

                    NSLog(@"%@", feedData);

                } else {

                    // Alert the user with the error
                    UIAlertView *twitterAlert = [[UIAlertView alloc] initWithTitle:kErrorTitle
                                                                           message:kErrorMessage
                                                                          delegate:nil
                                                                 cancelButtonTitle:@"Ok"
                                                                 otherButtonTitles:nil];
                    [twitterAlert show];


                }
            } else {

                // Alert the user with the error
                UIAlertView *twitterAlert = [[UIAlertView alloc] initWithTitle:kErrorTitle
                                                                       message:kErrorMessage
                                                                      delegate:nil
                                                             cancelButtonTitle:@"Ok"
                                                             otherButtonTitles:nil];
                [twitterAlert show];


            }


        });
    }];


}

知道可能是什么问题吗?我一开始以为是因为图片太大,所以我添加了将图片缩小到500 x 500的方法,但我得到了同样的错误。

在设备和模拟器上运行时都会发生此错误。

有没有人看到问题出在哪里或有任何额外的见解?谢谢!

最佳答案

在我的测试中,大于 1000x1000 像素的图像不会同步缩小,抛出 131 响应代码。不幸的是,没有记录。

确保图片小于 700kb 且小于 1000x1000 像素。 https://dev.twitter.com/rest/reference/post/account/update_profile_image

关于http - 将用户个人资料图片发布到 Twitter 时出现错误 131,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20437163/

相关文章:

javascript - Meteor:如何获取自定义跟踪系统的 IP 地址

c - 使用C语言调用HTTP Web Service

ios - iOS 中多部分表单数据请求的库

node.js - 用于在请求对象中保存原始发布数据的中间件不会是 "next"并导致超时

java - 推特提要 API

php - 如何使用 Twitter 直接消息流作为输入?

http - Safari 移动版和桌面版隐藏了完整的引用 URL : why?

python - 如何在 Python 中获取标准 HTTP header 名称列表

php - $_POST 中的问题

twitter - 在 Twitter 上验证 OAuth token