开发者

Sending message to Twitter creates an error message

I'm trying to get the following code to run (it's from the Heads First iPhone Development book - page 81), it's a twitter app, and the code blow runs when you press a button to send a simple text message to twitter:

//TWITTER BLACK MAGIC
    NSMutableURLRequest *theRequest=[开发者_开发百科NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@"http://username:password@twitter.com/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy 

    timeoutInterval: 60.0];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%", themessage] dataUsingEncoding:NSASCIIStringEncoding]];

    NSURLResponse* response;
    NSError* error;
    NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
    NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
    //END TWITTER BLACK MAGIC

and it does to a certain extent i.e the code runs but you can't see the result on Twitter - the resopnse I get back from Twitter in the debug window is:

  <request>/statuses/update.xml</request>
  <error>Client must provide a 'status' parameter with a value.</error>

Any ideas?


It looks like you should use '%@' instead of '%' in your format string:

[theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%@", themessage] dataUsingEncoding:NSASCIIStringEncoding]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜