So I use :
http://groups.google.com/group/plixi/web/sample-iphone-code-upload
Plixi API Document :
-(NSData*) UploadPlixi : (NSData*) imageData
{
NSString *apikey = [self GetApiKey:self.mediaService];
float piclongitude = 122;
float piclatitude = 40;
BOOL emptyMsg = (self.message==nil || [self.message length] == 0);
NSString *uploadAndPost = emptyMsg ? @"http://api.plixi.com/api/tpapi.svc/upload" : @"http://api.plixi.com/api/tpapi.svc/uploadandpost";
NSString *twitter_password = [self.password copy];
NSString *twitter_username = [self.userName copy];
NSString *twitter_msg = @"Plixi API is awesome!";
/*build XML like this, the Location & tags elements are optional everything else is required
*/
NSString *xml = [NSString stringWithFormat:@"http://api.plixi.com \" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">%@%@%@%@%@%@%@",
[NSString stringWithFormat:@"%@ ",apikey], //your developer apikey this is required
[NSString stringWithFormat:@"%.6f %.6f ",piclatitude,piclongitude],
[NSString stringWithFormat:@"%@ ",twitter_msg], //message you want to tweet
[NSString stringWithFormat:@"image/png "], //i'm using png in my code, change this to whatever you're using
[NSString stringWithFormat:@"%@ ",twitter_password], //twitter password
[NSString stringWithFormat:@"%@ ",@"tag1,tag2,tag3"], //comma seperated list of tags
[NSString stringWithFormat:@"%@ ",twitter_username]]; //twitter user name
//get UTF8Encoded XML String
NSMutableData *uploadPostData = [NSMutableData data];
[uploadPostData appendData:[xml dataUsingEncoding:NSUTF8StringEncoding]]; //write the XML as UTF8 encoded bytes first
[uploadPostData appendData:[NSData dataWithData:imageData]]; //write the bytes that represent the image next
//Create a post request
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:uploadAndPost]];
[request setHTTPMethod:@"POST"];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%d",[imageData length]] forHTTPHeaderField: @"TPAPIImageSize"]; //this is a custom header, tell the server what size the image is in bytes
[request addValue:[NSString stringWithFormat:@"%d",[uploadPostData length]] forHTTPHeaderField: @"Content-Length"]; //this is the size of the entire message size in bytes, not sure if this is autoset
[request setHTTPBody:uploadPostData];
//now send it away - slow code this is synchronous!
return [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
}
http://groups.google.com/group/plixi/web
With Regrads,
Dinesh Sharma
No comments:
Post a Comment