Life, Teams, and Software Engineering

Category: iphone

SA_OAuthTwitterEngine Search Error 400

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.

OCMock iPhone 4.1 SDK

I imagine that this is a common occurrence when a new version of the iPhone SDK comes out but I figured I’d put it out there for the droves of development teams who will take the plunge with the update this coming week.

If your iOS project relies on OCMock and you just upgraded to the iOS 4.1 SDK (and you upped the Base SDK on the target to 4.1) then chances are your unit test projects aren’t building.  To get it working again:

  1. Checkout the OCMock trunk:
  2. Open the OCMock project in XCode
  3. Change the Base SDK on the OCMockPhoneSim target to iOS Simulator 4.1 (see Base SDK vs. Active SDK for why).
  4. Build the target.
  5. Copy libOCMock.a and Headers from the build/$(CONFIG)-iphonesimulator folder to wherever you were keeping them before.
That should allow you to link and run but if your experience is anything like mine you’ll be getting a bunch of unexplained errors like “An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSection testName]: unrecognized selector sent to instance”.  Highly annoying but ultimately it will still report “X out of X tests passed” although with all those errors I’m less inclined to trust it.
Thanks to Vincent Daubry for pointing me in the right direction when he experienced the problem during the last major update.

Copyright © 2017 Life, Teams, and Software Engineering

Theme by Anders NorenUp ↑