I am trying to get facebook data using SLRequest iOS API, which seems to be working fine -
NSDictionary *parameters = @{};
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/home"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:feedURL
parameters:parameters];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
// something
}];
However, following this I make an HTTP POST request to one of my servers,
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [NSData dataWithBytes:[jsonData bytes] length:[jsonData length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
which POSTS the data fine (verified from the server logs), but I do not get any HTTP response for it in
connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
This used to be working fine without the SLRequest POST, and I am able to comment that piece out and it starts working again.
What am I missing here ?
The fix that work for me is not to use the SLRequest block loading and to use a NSURLConnection with the appropriate NSURLConnectionDelegate methods in the first instants. The second time you use this delegate the loading should be fine, try keeping all you loading in the same Utility Class, so they share the same delegate. For me it was issues with the twitters v1.1 API.
So in your code try removing the block and then you need to prepare the SLRequest:
Then use the NSURLConnectionDelegate Methods, with capturing the loaded NSData:
This fix was inspired by Keith Harrison post at : http://useyourloaf.com/blog/2013/06/24/migrating-to-the-new-twitter-search-api.html
So credit goes to him too.