timeout value for ios facebook sdk request - iphone

hey guys does the ios facebook sdk asynchronous request delegate allow developer to specify some sort of timeoutInterval value? i know that the nsURLRequest has a timeoutInterval value that u can set.
Thanks for your help.
scenario:
i make an async request call. the connection dies after the request call goes out and before the response comes back. currently, i have no way of detecting this. what i want is: i call line number 2. after 10 sec, no response comes back, line 5 would get execute. Or something along the line that there were an error.
1 - // async request call
2 - [facebook requestWithGraphPath:#"me/home" addParams:nil andDelegate:self];
3 - // delegate
4 - - (void) request :(FBRequest *)request didLoad:(id)result {}
5 - - (void) request :(FBRequest *)request didFailWithError :(NSError *)error {}

see Facebook ios SDK, FBRequest.m file at the beginning:
static const NSTimeInterval kTimeoutInterval = 180.0;
then it is used by a connect method. You can change it or patch the SDK so it could be set externally.
hope this helps

FBRequest.m applies it's timeoutInterval to NSMutableURLRequest, which ignores/overrides anything under 240 seconds. If your interested, read more about that here...
iPhone SDK: URL request not timing out
...otherwise it basically means the kTimeoutInterval in FBRequest.m is ignored if set to < 240, so don't bother with it.
I've just gone through this issue myself, I ended up using an NSTimer that will cancel the pending FBRequest's connection on timeout. see details here..
Facebook API - How to cancel Graph Request

Related

iphone App crashing After FbRequest method

I have made an iPhone App which has a "loginwithFacebook" button , the login procedure is working fine . but App crashes after passing through the FBRequest method "- (void)request:(FBRequest *)request didLoad:(id)result " and "- (void)connectionDidFinishLoading:(NSURLConnection *)connection " .
I tried to put some break point in these methods. Then , I was amaized to see that App is working After some delay with that i made putting the break points.
Is it something related to loading the connection or Delay of the content loading from
Fbrequest method ???
please help me ..
[NSNull lowercaseString] which means your one string is null and you are trying to apply lowercaseString method to that string. keep a null check condition before this method call or you can check why this string is null.
It may be related to the access token of Facebook. because when u log in with Facebook, you will get one access token, and that token is used everywhere, so try to check the access token as its not nil. and this is just my assumption but will request you to keep your code where the crash happened. else post the crash reason from console.

Ajax timeout in UIWebView

I'm working on an iOS app that displays a webpage through a UIWebView. The page contains between 20 and 40 buttons. Each one sends an ajax request to the server. It works for the most part, but the server is a desktop app and could close at any moment for any reason with no warning. With these ajax requests, there is no output displayed to the user so if the server went down, the user would have no idea. I would like to be able to be notified of an ajax timeout and then give the user the options to either try again or go back to the home screen. I can't seem to find a way to have the UIWebView be notified of any failed ajax requests.
At first I thought I could simply use the webView:didFailLoadWithError: method of the UIWebViewDelegate, but apparently it's not notified of failed ajax requests.
Any suggestions are greatly appreciated
If when a failure occurs, there is JavaScript code that is invoked in your Ajax failure handlers that makes a location.href change then the UIWebViewDelegate shouldStartLoadWithRequest: method will get called, giving you the chance to do something whenever there is a failure. i.e.
In the Ajax timeout handling code:
window.location.href = "myscheme://AjaxFailure";
In your UIWebViewDelegate handling code:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"shouldStartLoadWithRequest: url: %#", [[request URL] absoluteString]);
NSURL *URL = request.URL;
if ([URL.scheme isEqualToString:#"myscheme"])
{
... notify the user there was an error

How would I issue two Facebook request in the same class? iOS SDK

I want to get all photos from the different albums of a user. So I write a request me/albums then in didLoad I get an array of albums, which I can use the id of each album to issue a new request albumId/photos but how should I do that? Should I add the request in the didLoad, but then, how would I know them apart?
Ok this is how I do it might not be the best way to go about it but it works. In the did load
-(void)request:(FBRequest *)request didLoad:(id)result {
NSString *requestType =[request.url stringByReplacingOccurrencesOfString:#"https://graph.facebook.com/" withString:#""];
NSLog(#"request %#",requestType); }
Now the requestType would be either me/albums or albumId/photos. Put in a couple a conditional if-statements and you are good to go. And yes you can add the new request for fetching photos from the albums in the didLoad in the if condition that matches me/albums (meaning you got some result for that request ie the albums array). The next time you hit the didLoad it would be for the photos in the albums. Hope that helps.
you could also keep the refs to the FBRequest instance returned by each requestWithGraphPath call and match them with the ref. you get when the delegate methods are called back.

Using retweeted_by API with MGTwitterEngine - keeps on returning error 404

I'm trying to add a method to MGTwitterEngine to use twitter's retweeted_by API ( http://dev.twitter.com/doc/get/statuses/:id/retweeted_by ).
Here is what I've added to MGTwitterEngine.m (all the OAuth stuff is done, the other methods inside the engine work fine)
-(NSString *)getUsersWhoRetweetedTweetWithID:(unsigned long)ID {
NSString *path = [NSString stringWithFormat:#"statuses/70482402362933249/retweeted_by.xml"];
return [self _sendRequestWithMethod:nil path:path queryParameters:nil body:nil
requestType:MGTwitterUsers
responseType:MGTwitterUsers];
}
Note: I've already included the .xml format and a status ID - just to ensure there's nothing wrong with the data I'm passing on. When I call [_engine getUsersWhoRetweetedTweetWithID:0]; from my app controller, error 404 is returned "The operation couldn't be completed. (HTTP error 404.)".
I've tried it with a parameters NSDictionary & tried changing the request & response types.
Currently, I don't make use of MGTwitterEngine to check who RTd a tweet, I just use a non OAuth'd method - however this will not return protected users who RTd a tweet.
Can anyone give me a point in the right direction - it's being driving me crazy for the past few days! I really appreciate any input :)
Take a look here.....
How to do a RETWEET on an iPhone twitter app (MGTwitterEngine)
MGTwitterEngine does not support re-tweet method yet .. you have to manually add the parse to MGTwitterEngine .h and .m then the call out would be [_engine sendRetweet:(unsigned Long)];
Now I am in the process of trying to determine how you call out the unsigned long...if any one else has an answer to that I would be happy to hear it myself.

FaceBook iOS - check if my facebook app is allready authorized

My question is how to check if my FaceBook app is already authorized for posts by the user, can't find any info on that.
I'm using:
Facebook* facebook = [[Facebook alloc] initWithAppId:#"1234567"];
[facebook authorize:[NSArray arrayWithObjects:#"read_stream", #"offline_access",nil] delegate:self];
A dialog pops up asking me to authorize the app, when done i'm all fine, can do a:
[facebook dialog:#"feed" andDelegate:self];
to post notes on that app.
But, if the user blocks or removes the app i want to do the authorize again before showing the dialog for posting, can't find a way of getting that kind of info before calling authorize.
Any help is appreciated.
Thanks.
I had to deal with this issue too.
When calling the dialog method, you send a delegate that should conform to FBDialogDelegate, which has a method that is called when the dialog fails to load due an error. But in the case the app has been unauthorized, the dialog shows a login screen to the user, but after setting the user and password, a second form appears, letting the user know that an error has occurred. The delegate is also called, but the error received just states that he method has failed with no exact reason why, or even an error number. This method should be called with the correct error, before anything, so the application could act accordingly.
So I found a work around, maybe this is not the best way, but it certainly works. Any call that you do to the Facebook graph api via a request, will fail if the app has been unauthorized by the user. So what I did was to check that before calling the feed dialog method.
Add the following line where you need to test if the app is still authorized:
if ([facebook isSessionValid])
//isSessionValid only checks if the access token is set, and the expiration date is still valid. Lets make a call and see if we really are authorized to post to this user from this app.
[facebook requestWithGraphPath:#"me" andDelegate:self];
else
//authorize Facebook connect
This will just call the method that returns the basic information from the user. If everything is fine, the following method will be called from the delegate:
- (void)request:(FBRequest *)request didLoad:(id)result
{
//Everything is ok. You can call the dialog method. It should work.
}
If the app has been unauthorized by the user, the following method from the delegate will be called:
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error;
{
NSString *type = [[[error userInfo] objectForKey:#"error"] objectForKey:#"type"];
if (type)
{
if ([type isEqualToString:#"OAuthException"]) //aha!
{
//user has unauthorized the app, lets logout from Facebook connect. Also clear the access and expiration date tokens
[facebook logout:self];
//Call the authorize method again. Or let the user know they need to authorize the app again.
}
}
}
So, as I said before, not the best way, but gets the job done. Hopefully, Facebook will add a method to check for this specific scenario, or add a new method to the delegate that deals with the unauthorized app issue.
I'm not sure how exactly to do it with Facebook's SDK, but you can use FQL to query the permissions. The query URL would look something like
https://api.facebook.com/method/fql.query?query=SELECT+uid,+read_stream,+offline_access+FROM+permissions+WHERE+uid=me()&access_token=...
It looks like requestWithMethodName:andParams:andHttpMethod:andDelegate: passing fql.query as the method is the way to go, as long as you can arrange for isSessionValid to be true (or somehow supply access_token in the params yourself).