2012-11-27 6 views
0

나는 Facebook, Twitter 및 Tumblr 공유와 같은 공유 기능이있는 iOS 응용 프로그램에서 작업 중입니다. 나는 Tumblr 외에 모든 공유를했습니다. 나는 이것에 대해 많은 연구를했습니다. 인터넷 검색을 많이했는데 Tumblr 공유에서 아무 것도 발견되지 않았습니다. 내가 어떤 Authentication failed 오류가이 코드를 실행 할 때마다Xcode를 사용하여 Tumblr에 텍스트를 공유하는 방법

- (void)shareOvertumblr:(id)sender 
{ 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 
           initWithURL: 
           [NSURL URLWithString:@"http://www.tumblr.com/api/write"]]; 
[request setHTTPMethod:@"POST"]; 
//tell the server to expect 8-bit encoded content as we're sending UTF-8 data, 
//and UTF-8 is an 8-bit encoding 
[request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"]; 
//set the content-type header to multipart MIME 
[request addValue: [NSString stringWithFormat:@"multipart/form-data; boundary=%@",[NSString MIMEBoundary]] forHTTPHeaderField: @"Content-Type"]; 

//create a dictionary for all the fields you want to send in the POST request 
NSDictionary* postData = [NSDictionary dictionaryWithObjectsAndKeys: 
          @"myEmailAddress", @"email", 
          @"password", @"password", 
          @"regular", @"type", 
          @"myTitle", @"title", 
          @"Hiiii How ruuu", @"body", 
          nil]; 
//here inPlace of these EmailAddress and Password using my correct emailAdress and Password 
//set the body of the POST request to the multipart MIME encoded dictionary 
[request setHTTPBody: [[NSString multipartMIMEStringWithDictionary: postData] dataUsingEncoding: NSUTF8StringEncoding]]; 
[NSURLConnection connectionWithRequest:request delegate:self]; 
} 

    /*Here is The Category */ 
    @interface NSString (MIMEAdditions) 
+ (NSString*)MIMEBoundary; 
+ (NSString*)multipartMIMEStringWithDictionary:(NSDictionary*)dict; 
@end 

@implementation NSString (MIMEAdditions) 
//this returns a unique boundary which is used in constructing the multipart MIME body of the POST request 
+ (NSString*)MIMEBoundary 
{ 
static NSString* MIMEBoundary = nil; 
if(!MIMEBoundary) 
    MIMEBoundary = [[NSString alloc] initWithFormat:@"----_=_YourAppNameNoSpaces_%@_=_----",[[NSProcessInfo processInfo] globallyUniqueString]]; 
return MIMEBoundary; 
} 
//this create a correctly structured multipart MIME body for the POST request from a dictionary 
+ (NSString*)multipartMIMEStringWithDictionary:(NSDictionary*)dict 
{ 
NSMutableString* result = [NSMutableString string]; 
for (NSString* key in dict) 
{ 
    [result appendFormat:@"--%@\nContent-Disposition: form-data; name=\"%@\"\n\n%@\n", [NSString MIMEBoundary],key,[dict objectForKey:key]]; 
} 
[result appendFormat:@"\n--%@--\n",[NSString MIMEBoundary]]; 
return result; 
} 
@end 

/*Connection Delegate Methods*/ 
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
[self.view setUserInteractionEnabled:YES]; 

} 
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
webData = [[NSMutableData alloc] initWithLength:0]; 
// webData is The NSMutable data 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 

NSString* responseString = [[NSString alloc] initWithData: webData 
               encoding: NSUTF8StringEncoding]; 

NSLog(@"Response String %@",responseString); 
// here i got Authentication failed as Response ..... 

} 


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 
[webData appendData:data]; 

} 

: 여기에 현재 텀블러를 통해 텍스트를 공유하기 위해 사용하여 내 코드입니다. 여러 스레드에서 동일한 문제가 발생했습니다. Here is the link I have tried 하지만 불행히도 지금까지 운이 없습니다. 도와주세요. 대신에 자신의 코드의

답변

1

, 당신은 코드 불과 3 라인 앱에 전체 공유 기능을 추가합니다 ShareKit

를 사용할 수 있습니다.

ShareKit은 모든 공유 기능을 즉시 추가하기 위해 모든 iPhone 또는 iPad 앱에 포함시킬 수있는 오픈 소스 프레임 워크입니다.

당신은 단 몇 줄의 코드에 Tumblr 공유의 URL, 이미지 및 텍스트를 추가 ShareKit를 사용할 수 있습니다.

공유 텍스트

+ (SHKItem *)text:(NSString *)text;

NSString *someText = @"This is a blurb of text I highlighted from a document."; 
SHKItem *item = [SHKItem text:someText]; 

당신이 볼 수있는 자세한 내용

+0

here 그래 내가 Sharekit도 시도하고 shareKit는 텀블러를 통해 텍스트를 게시 나에게 도움이되지 않았다. ... 로그인 오류가 발생했습니다 ... – Kamarshad

관련 문제