user446299
user446299

Reputation: 71

MGTwitterEngine - isUser:receivingUpdatesFor: always return HTTP error 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.

Upvotes: 2

Views: 1248

Answers (1)

Alex Morales
Alex Morales

Reputation: 2791

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!

Upvotes: 2

Related Questions