1

I'd like to attach the location of the user to a TWRequest. I've tried to modify the url (with something like this: "http://api.twitter.com/1/statuses/update.json?lat=37.76893497&long=-122.42284884") but the response was "401 Unauthorized" or "400 Bad Request".

My TWRequest:

TWRequest *postRequest = [[TWRequest alloc] initWithURL:
                                               [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:[tweet text] forKey:@"status"] requestMethod:TWRequestMethodPOST];

Thanks in advance.

Netnyke
  • 151
  • 1
  • 1
  • 8

1 Answers1

2

You attempt to perform request which requires authorization. Just initialize account property. Look at a good article about Twitter API: http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html

UPD: And you can't mix POST and GET variables, I mean you have to specify all parameters to NSDictionary (POST parameters), not to URL.

NSURL *updateURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[tweet text], @"status",
    @"-122.42284884", @"long",
    @"37.76893497", @"lat", nil];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:updateURL                  
                                             parameters:dict
                                          requestMethod:TWRequestMethodPOST];

UPD2: If geo-location isn't work, check if location is enabled for twitter account (go to Twitter site - Settings - Account - Tweet Location). Look at the REST API documentation on Twitter site update request section:

About geo

Any geo-tagging parameters in the update will be ignored if geo_enabled for the user is false (this is the default setting for all users unless the user has enabled geolocation in their settings)

Cœur
  • 37,241
  • 25
  • 195
  • 267
4ndrew
  • 15,354
  • 2
  • 27
  • 29
  • Thanks for the answer. How Can I enable "geo_enabled" ? – Netnyke Jan 08 '12 at 21:26
  • @Netnyke As I said early, go to Twitter site - Settings - Account - Tweet Location (enable checkbox). By default it is disabled for all accounts on twitter. – 4ndrew Jan 08 '12 at 23:55
  • :O I didn't pay attention at the 2nd update.. It works like a charm! Thank you! – Netnyke Jan 09 '12 at 13:33