1

我想将用户的位置附加到 TWRequest。我试图修改 url(使用类似这样的内容:)"http://api.twitter.com/1/statuses/update.json?lat=37.76893497&long=-122.42284884"但响应是“401 Unauthorized”或“400 Bad Request”。

我的 TW 请求:

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

提前致谢。

4

1 回答 1

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 文档

关于地理

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

于 2012-01-08T12:26:05.160 回答