views:

73

answers:

3

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.

A: 

Hello,

I have exactly the same issue, did you manage to solve it?

If I do I'll let you know.

almosnow
A: 

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!

almosnow
@zhwtz12345 That particular request returns in the delegate callback: - (void)miscInfoReceived:(NSArray *)statuses forRequest:(NSString *)requestIdentifier;
almosnow
A: 

I followed your way, it succeed. But I still cannot get false or true value from the function. I could see request succeed. But Where should find out the return value by the isUser function, it suppose to have a true/false return value. right?

zhwtz12345