【问题标题】:How to attach geolocation to a tweet using TWRequest如何使用 TWRequest 将地理位置附加到推文
【发布时间】:2012-02-05 08:03:15
【问题描述】:

我想将用户的位置附加到 TWRequest。我尝试修改网址(使用类似这样的内容:"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];

提前致谢。

【问题讨论】:

    标签: iphone ios twitter twrequest


    【解决方案1】:

    您尝试执行需要授权的请求。只需初始化帐户属性。 看一篇关于 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 站点 - 设置 - 帐户 - 推文位置)。看看推特网站上的REST API documentationupdate request section

    关于地理位置

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

    【讨论】:

    • 感谢您的回答。如何启用“geo_enabled”?
    • @Netnyke 正如我之前所说,转到 Twitter 站点 - 设置 - 帐户 - 推文位置(启用复选框)。默认情况下,Twitter 上的所有帐户都禁用它。
    • :哦,我在第二次更新时没有注意。它就像一个魅力!谢谢!
    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多