我已经成功地收到了下面的twitter数据(在用户登录之后),尽管我已经搜索了很多,但我还没有找到一种方法可以很好地在用户的twitter配置文件中发布图像。有详细的教程吗?
oauth_token=xxxxxxxxjU8gs6&oauth_token_secret=xxxxD7ITa&user_id=xxx73&screen_name=manostijeras&oauth_verifier=xx07谢谢
PS:我使用本教程接收twitter oauth data http://www.icodeblog.com/2010/09/16/dealing-with-the-twitter-oauth-apocalypse/
发布于 2013-12-02 12:17:07
这是程序->
OAToken *token = [[OAToken alloc] initWithKey:OauthAccessToken secret:OauthAccessSecrateKey]; //Set user Oauth access token and secrate key
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:ConsumerToken secret:ConsumerSecrateKey]; // Application cosumer token and secrate key
// Url for upload pictures
NSURL *finalURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json];
OAMutableURLRequest *theRequest = [[OAMutableURLRequest alloc] initWithURL:finalURL
consumer:consumer
token:token
realm: nil
signatureProvider:nil];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:120];
[theRequest setHTTPShouldHandleCookies:NO];
// Set headers for client information, for tracking purposes at Twitter.(This is optional)
[theRequest setValue:@"TestIphone" forHTTPHeaderField:@"X-Twitter-Client"];
[theRequest setValue:@"1.0" forHTTPHeaderField:@"X-Twitter-Client-Version"];
[theRequest setValue:@"http://www.TestIphone.com/" forHTTPHeaderField:@"X-Twitter-Client-URL"];
NSString *boundary = @"--Hi all, First Share"; // example taken and implemented.
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[theRequest setValue:contentType forHTTPHeaderField:@"content-type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"status\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@",@"latest upload"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media[]\"; filename=\"vizllx_pic1.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:UIImageJPEGRepresentation([UIImage imageNamed:@"vizllx_pic.png"], 0.5)]];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest prepare];
NSString *oAuthHeader = [theRequest valueForHTTPHeaderField:@"Authorization"];
[theRequest setHTTPBody:body];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:&response
error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];https://stackoverflow.com/questions/20328001
复制相似问题