我想将用户的位置附加到 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/