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

标签 iphone ios twitter twrequest

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

提前致谢。

最佳答案

您尝试执行需要授权的请求。只需初始化帐户属性。 看一篇关于 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 documentation在 Twitter 网站上 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)

关于iphone - 如何使用 TWRequest 将地理定位附加到推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8777370/

相关文章:

ios - 从 Storyboard 中实例化几个可拖动的图 block - 附上测试代码和屏幕截图

ios - 将 Iphone 应用程序更新为 Swift Coding

ios - 如何从 web 服务处理 JSON 中的撇号?

ios - UIViewController – 自定义关闭转换的问题

ios - 简单的 Xcode Hello World 显示控件然后它们立即消失

iphone - 以编程方式创建 UISwitch

ios - 将图像从 iOS 应用程序发送到服务器的正确方法

web-services - 从 Twitter 获取稳定的消息流

android - Parse.com 身份验证错误 : Unable to respond to any of these challenges: {oauth=www-authenticate: OAuth realm ="https://api.twitter.com"}

ios - Twitter API 如何知道一个用户是否关注另一个用户?