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

发布于 2024-09-18 12:19:48 字数 1142 浏览 7 评论 0原文

我在实现 MGTwitterEngine 的 isUser:receivingUpdatesFor: 方法以检查用户是否在 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,我的请求也总是失败,这是日志消息:

Request isRequestIdentifier : E8284E63-A5B0-4C18-A3DB-B4F0A5E6048E failed with error :错误域=HTTP代码=400“操作无法完成。(HTTP错误400。)”

知道我做错了什么吗?

感谢您的帮助。

I have some problem to implement the method isUser:receivingUpdatesFor: from the MGTwitterEngine in order to check if a user is following another user on Twitter. Here is my code :

//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);
    }
}

It seems to work but I always have failed request even when I'm sure that the user1 is following the user2, here is the log message:

Request isRequestIdentifier : E8284E63-A5B0-4C18-A3DB-B4F0A5E6048E failed with error: Error Domain=HTTP Code=400 "The operation couldn’t be completed. (HTTP error 400.)"

Any idea on what I'm doing wrong?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁憨憨 2024-09-25 12:19:48

我想出来了:)!

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

  • (NSString *)isUser:(NSString *)username1receivingUpdatesFor:(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”函数采用path 不会将参数写入 url,这就是我们收到 400 Bad Request 错误的原因。

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

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

工作完美!

I figured it out :)!

Go to MGTwitterEngine.m and look for the declaration of:

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

You will find this code:

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

That causes the problem, becasue the 'next' function that takes the path does NOT writes the params into the url, and that's why we were getting that 400 Bad Request error.

The 'quick and dirty' fix I did is to comment all those lines and add:

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

Works flawless!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文