2012-03-07 11 views
0

Twitterにjpg画像をアップロードしようとしています。私は@ "icon.png"を何度でもアップロードすることができますが、アップロードするにはjpgを得ることができません。私はいつもTwitterからエラー403を返す。これは私のコードです:JPG画像をTwitterにアップロード

ACAccount *twitterAccount = [arrayOfAccounts objectAtIndex:0]; 


UIImage *image =[UIImage imageNamed:file]; //file is the name of a jpg image. If replaced with @"icon.png" the upload works 


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

[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"]; //I've tried this with UIImageJPEGRepresentation(image, 80) and multipart/jpg and jpeg to no avail 


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

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

助けてください!

私はそれが

UIImage *image =[UIImage imageNamed:@"background.png"]; //This file is copied to the device when the app is built. 

に動作します。しかし、私はこれを使用している場合である私は、このパスとファイル名がそのままの画像

UIImage *image =[UIImage imageNamed:[NSString stringWithFormat:@"%@/%@", dir, file]]; 
を引き上げないことを確認しているにもかかわらず、動作しないの下を使用している場合

私は間違っていますか?おかげ

/// SOLUTION 私は馬鹿であってもよいし、私を十字架しないでください、しかし、ここで私はこれはPNGやJPG両方をせずにアップロードすることができます

UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", dir, file]]; 

にUIImageを変更するために必要なものです問題。愚かな間違いだが、少なくともそれは今働いている。返信ありがとう!

+0

「403」は認証エラーであるため、「twitterAccount」を確認してください。 – Shahzeb

+0

はい、私は、それは読み取りと書き込みの両方のアクセスが設定されています。アプリにもアクセスが許可されています。私が以前に言ったように、私はicon.pngを問題なくアップロードできます。私が必要とするファイル形式であるjpgをアップロードしようとすると、それは403を返します。非常にイライラします!迅速な返信をありがとう!ちなみに、私はpngをアップロードするリターンは200です。私はもう一度これを確認しましたが、別のpngをアップロードしました。 – mejim707

+0

jpgの場合は、imageNamedをファイルの名前だけ渡しているのですか?また、.jpg拡張子を追加していますか? – Abizern

答えて

1

403エラーは、Twitterからエラーが発生したことを意味します。同じTwitterアカウントから同じコンテンツを2回共有することはできません。同じ写真をアップロードする場合は、まずTwitterアカウントから削除してから、再度アップロードしてください。それ以外の場合は、別の画像をアップロードしてください。

関連する問題