MGTwitterEngine - isUser:receivingUpdatesFor:总是返回HTTP错误400?

时间:2010-09-13 13:04:52

标签: iphone objective-c twitter mgtwitterengine

我有一些问题要实现方法isUser:receivingUpdatesFor:来自MGTwitterEngine,以检查用户是否在Twitter上跟踪另一个用户。这是我的代码:

//Here is how I call the method (isRequestIdentifier is an NSString declare in the .h)
isRequestIdentifier = [[twitterEngine isUser:user1 receivingUpdatesFor:user2] retain];
NSLog(@"user1 : %@ - user2 : %@", user1, user2);
NSLog(@"isRequestIdentifier : %@",isRequestIdentifier);

#pragma mark TwitterEngineDelegate

- (void) requestSucceeded: (NSString *) requestIdentifier {
    if ([requestIdentifier isEqualToString:isRequestIdentifier]) {
        NSLog(@"Request isRequestIdentifier %@ succeeded", requestIdentifier);
    }
}

- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
    if ([requestIdentifier isEqualToString:isRequestIdentifier]) {
        NSLog(@"Request isRequestIdentifier : %@ failed with error: %@", requestIdentifier, error);
    }
}

它似乎工作但我总是有失败的请求,即使我确定user1跟随user2,这是日志消息:

请求isRequestIdentifier:E8284E63-A5B0-4C18-A3DB-B4F0A5E6048E失败并显示错误:错误域= HTTP代码= 400“操作无法完成。(HTTP错误400。)”

对我做错了什么的想法?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

我明白了:)!

转到MGTwitterEngine.m并查找以下声明:

  • (NSString *)isUser:(NSString *)username1 receivingUpdatesFor:(NSString *)username2

您会找到以下代码:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:username1 forKey:@"user_a"];
[params setObject:username2 forKey:@"user_b"];

NSString *path = [NSString stringWithFormat:@"friendships/exists.%@", API_FORMAT];

这会导致问题,因为采用路径的'next'函数不会将params写入url,这就是我们收到400 Bad Request错误的原因。

我做的“快速而肮脏”的修复是评论所有这些行并添加:

NSString *path = [NSString stringWithFormat:@"friendships/exists.%@?user_a=%@&user_b=%@", API_FORMAT, username1, username2];

完美无瑕!