2012-01-08 69 views
1

我想将用户的位置附加到TWRequest。我试图修改网址(像这样的:"http://api.twitter.com/1/statuses/update.json?lat=37.76893497&long=-122.42284884"),但答复是“401未授权”或“400错误请求”。如何使用TWRequest将地理位置附加到推文

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

在此先感谢。

回答

2

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

UPD:你不能混用POST和GET变量,我的意思是,你必须指定所有参数NSDictionary中(POST参数),而不是网址。

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网站 - 设置 - 帐户 - 分享Tweet位置)。看看REST API documentation在Twitter网站update request section

关于GEO如果geo_enabled用户

在更新任何地理标记参数将被忽略是假的(这是默认 设置对于所有用户,除非用户在其 设置中启用了地理位置)

+0

此方法有效,但该位置未在Twitter上显示。 – Netnyke 2012-01-08 17:28:52

+0

@Netnyke检查地理设置(我已更新了我的答案) – 4ndrew 2012-01-08 19:53:51

+0

感谢您的回答。我如何启用“geo_enabled”? – Netnyke 2012-01-08 21:26:10

相关问题