It may be deliberate that this function doesn’t work but that doesn’t make much sense.  I’m trying to use SA_OAuthTwitterEngine as the sole Twitter engine in my app but I’m having problems with the getSearchResultsForQuery: method (yes, I’ve hooked up the YAJL library).  Every single time I send a request using the getSearchResultsForQuery: selector on my SA_OAuthTwitterEngine I’m get the following error:

"The operation couldn’t be completed. (HTTP error 400.)"

MGTwitterEngine produces no such error.  You wouldn’t think calling this selector would be a problem since it inherits directly from MGTwitterClient and therefore provides the interface, but actually it is.  The problem lies in SA_OAuthTwitterEngine’s implementation of

  1. - (NSString *)_sendRequestWithMethod:(NSString *)method
  2.                                 path:(NSString *)path
  3.                      queryParameters:(NSDictionary *)params
  4.                                 body:(NSString *)body
  5.                          requestType:(MGTwitterRequestType)requestType
  6.                         responseType:(MGTwitterResponseType)responseType;

which overrides the default in the base MGTwitterEngine.  It’s described quite nicely in a comment but does nothing to explain the consequences of doing it this way.

  1. // ——————————————————————————-
  2. // mdificatfrom the base clase
  3. // the base class appends parameters here
  4. // ——————————————————————————-
  5. //    if (params) {
  6. //        fullPath = [self _queryStringWithBase:fullPath parameters:params prefixed:YES];
  7. //    }
  8. // ——————————————————————————-

The problem is that it doesn’t consider which type of MGTwitterRequestType is being used before making the decision to construct an OAuth request.  Certain actions simply don’t require an OAuth-formatted request, and in this case it just plain doesn’t work.  MGTwitterSearchRequest and MGTwitterSearchCurrentTrendsRequest are two types that I don’t believe require authentication, and therefore have no use for OAuth requests.  To fix the problem for this particular request type add the following code to the beginning of SA_OAuthTwitterEngine’s implementation of _sendRequestWithMethod:

  1. //Defer work to super because these requests don’t support OAuth
  2. if (requestType == MGTwitterSearchRequest || requestType == MGTwitterSearchCurrentTrendsRequest) {
  3.     return [super _sendRequestWithMethod:method path:path queryParameters<:params body:body requestType:requestType responseType:responseType];
  4. }

This certainly beats lugging around an instance of each class, one for reading and one for writing.  Hopefully this helps someone out, it was driving me nuts.

After using GeSHi I have now decided that I need a new blogger theme….but one thing at a time.  Back to XCode.