Sahar Lepa Sahar Lepa - 7 days ago 7
iOS Question

Facebook friend request dialog stopped working on UIWebView

I implemented the Add Friend dialog on iPhone using the post on stackoverflow:

Facebook friends dialog returns "Unknown method" error, it's implemented for Android but easy to convert to iPhone.

It worked fine until a few days ago when it stopped working and now it's throwing me an error:

An error occurred with HitMe. Please try again later.

API Error Code: 3

API Error Description: Unknown method

Error Message: This method isn't supported for this display type

I tried to search in facebook roadmap: https://developers.facebook.com/roadmap/ but couldn't find any mentioning of the change, did anyone experience this issue or know another way to implement the "Friend Request" dialog on iPhone?

This is the changes I made to the Facebook 2.0 sdk to implement the "Friend Request" dialog:

in dialog:andParams:andDelegate: method in Facebook.m I replaced the original code by the following code:

-(void)dialog:(NSString *)action
andParams:(NSMutableDictionary *)params
andDelegate:(id <FBDialogDelegate>)delegate {

[_fbDialog release];

NSString *dialogURL;

if ([action isEqualToString:kFriends])
{
dialogURL = [kDialogBaseURLForFriends stringByAppendingString:action];
}
else
{
dialogURL = [kDialogBaseURL stringByAppendingString:action];
}

if ([action isEqualToString:kFriends])
{
[params setObject:@"popup" forKey:@"display"];
}
else
{
[params setObject:@"touch" forKey:@"display"];
}

[params setObject:kSDKVersion forKey:@"sdk"];
[params setObject:kRedirectURL forKey:@"redirect_uri"];

if ([action isEqualToString:kLogin]) {
[params setObject:@"user_agent" forKey:@"type"];
_fbDialog = [[FBLoginDialog alloc] initWithURL:dialogURL loginParams:params delegate:self];
} else {
[params setObject:_appId forKey:@"app_id"];
if ([self isSessionValid]) {
[params setValue:[self.accessToken stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
forKey:@"access_token"];
[self extendAccessTokenIfNeeded];
}

// by default we show dialogs, frictionless cases may have a hidden view
BOOL invisible = NO;

// frictionless handling for application requests
if ([action isEqualToString:kApprequests]) {
// if frictionless requests are enabled
if (self.isFrictionlessRequestsEnabled) {
// 1. show the "Don't show this again for these friends" checkbox
// 2. if the developer is sending a targeted request, then skip the loading screen
[params setValue:@"1" forKey:@"frictionless"];
// 3. request the frictionless recipient list encoded in the success url
[params setValue:@"1" forKey:@"get_frictionless_recipients"];
}

// set invisible if all recipients are enabled for frictionless requests
id fbid = [params objectForKey:@"to"];
if (fbid != nil) {
// if value parses as a json array expression get the list that way
SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
id fbids = [parser objectWithString:fbid];
if (![fbids isKindOfClass:[NSArray class]]) {
// otherwise seperate by commas (handles the singleton case too)
fbids = [fbid componentsSeparatedByString:@","];
}
invisible = [self isFrictionlessEnabledForRecipients:fbids];
}
}

_fbDialog = [[FBDialog alloc] initWithURL:dialogURL
params:params
isViewInvisible:invisible
frictionlessSettings:_frictionlessRequestSettings
delegate:delegate];
}

[_fbDialog show];


}

where kFriends is @"friends" and kDialogBaseURLForFriends is @"https://facebook.com/dialog/"

Answer

I'm seeing the same problem here when using the Facebook Send Dialog (https://www.facebook.com/dialog/send?....) API calls.

Calls that have been running fine for months in iOS and Android apps now fail with API Error Code: 3 like mentioned above.

I've tried leaving out display=iframe altogether, or changing to other display types like popup etc. It still doesn't work. The docs at http://developers.facebook.com/docs/reference/dialogs/ still mentions iOS and Android as valid use cases for these type of dialogs. Trying out the same URLs in a desktop browser works fine.

Update: Found a workaround that works for Android at least. Simply change the useragent of the webview container:

webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1");

This gets the Send Dialog working for me on Android again at least. It's ugly but it works (for now).