2012-03-07 3 views
0

트위터에 jpg 이미지를 업로드하려고합니다. @ "icon.png"을 원하는만큼 여러 번 업로드 할 수 있지만 jpg를 업로드 할 수없는 것 같습니다. 나는 항상 트위터에서 오류 403을 되 찾는다. 내 코드 :트위터에 JPG 이미지 업로드

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:[NSString stringWithFormat:@"%@/%@", dir, file]]; 
을 당겨 그대로한다는 것을 확인했다하더라도,이 작동하지 않는 것입니다 사용하는 경우는,

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

작동하지만 아래 내가 사용하는 경우

내가 뭘 잘못하고 있니? 감사합니다

/// 솔루션 내가 바보가 될 수있다, 나는이 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 계정에서 사진을 제거한 다음 다시 업로드해야합니다. 그렇지 않으면 다른 그림을 업로드하십시오.