为iPhone集成twitpic OAuth

为iPhone集成twitpic OAuth,iphone,oauth,twitpic,Iphone,Oauth,Twitpic,如何与OAuth集成以发布来自iPhone的图像?有什么帮助或指导吗?目前我正在做 NSURL *twitpicURL = [NSURL URLWithString:@"http://api.twitpic.com/2/upload.format"]; theRequest = [NSMutableURLRequest requestWithURL:twitpicURL]; [theRequest setHTTPMethod:@"POST"]; // S

如何与OAuth集成以发布来自iPhone的图像?有什么帮助或指导吗?目前我正在做

        NSURL *twitpicURL = [NSURL URLWithString:@"http://api.twitpic.com/2/upload.format"];
    theRequest = [NSMutableURLRequest requestWithURL:twitpicURL];
    [theRequest setHTTPMethod:@"POST"];

    // Set the params
    NSString *message = theMessage;

    [theRequest addValue:@"http://api.twitter.com/" forHTTPHeaderField:@"OAuth realm"];
    [theRequest addValue:TWITPIC_API_KEY forHTTPHeaderField:@"oauth_consumer_key"];
    [theRequest addValue:@"HMAC-SHA1" forHTTPHeaderField:@"oauth_signature_method"];
    [theRequest addValue:USER_OAUTH_TOKEN forHTTPHeaderField:@"oauth_token"];
    [theRequest addValue:USER_OAUTH_SECRET forHTTPHeaderField:@"oauth_secret"];
    [theRequest addValue: @"1272325550" forHTTPHeaderField:@"oauth_timestamp"];
    [theRequest addValue:nil forHTTPHeaderField:@"oauth_nonce"];
    [theRequest addValue:@"1.0" forHTTPHeaderField:@"oauth_version"];
    [theRequest addValue:nil forHTTPHeaderField:@"oauth_signature"];

    NSMutableData *postBody = [NSMutableData data];
    [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"source\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithFormat:@"lighttable"] dataUsingEncoding:NSUTF8StringEncoding]];

    // Message
    [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"message\"\r\n\r\n%@", message]dataUsingEncoding:NSUTF8StringEncoding]];

    // Media
    [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media\"; filename=\"%@\"\r\n", @"doc_twitpic_image.jpg"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithFormat:@"Content-Type: image/jpg\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // data as JPEG

    [postBody appendData:[[NSString stringWithFormat:@"Content-Transfer-Encoding: binary\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[NSData dataWithData:image]];

    [theRequest setHTTPBody:postBody];
    [theRequest setValue:[NSString stringWithFormat:@"%d", [postBody length]] forHTTPHeaderField:@"Content-Length"];    
    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
看看图书馆

如果您决定使用它,则必须将其编译为一个静态库,或者只包含标题(请参阅以获取解释)。

查看该库


如果您决定使用它,您必须将其编译为一个静态库,或者只包含标题(请参阅以获取解释)。

使用用于iPhone的GSTwitPicEngine:


在iPhone上使用GSTwitPicEngine:


如果答案解决了您的问题,请接受答案。:)如果解决了您的问题,请接受答案。:)