如何使用TWRequest将地理定位附加到推文

时间:2012-01-08 12:09:23

标签: iphone ios twitter twrequest

我想将用户的位置附加到TWRequest。我试图修改网址(例如:"http://api.twitter.com/1/statuses/update.json?lat=37.76893497&long=-122.42284884"),但回复是“401 Unauthorized”或“400 Bad Request”。

我的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];

提前致谢。

1 个答案:

答案 0 :(得分:2)

您尝试执行需要授权的请求。只需初始化帐户属性即可。 看一篇关于Twitter API的好文章:http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html

UPD: 而且您无法混合POST和GET变量,我的意思是您必须为NSDictionary指定所有参数(POST参数),而不是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: 如果地理位置不起作用,请检查是否为Twitter帐户启用了位置(转到Twitter网站 - 设置 - 帐户 - 推文位置)。查看Twitter网站REST API documentation上的update request section

  

关于地理位置

     

如果用户的geo_enabled为false,则会忽略更新中的任何地理标记参数(这是默认值)   除非用户已在其中启用了地理定位,否则为所有用户设置   设置)

相关问题