0

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/"

Community
  • 1
  • 1
Sahar Lepa
  • 107
  • 1
  • 5

2 Answers2

3

Its works for IOS6.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([(NSMutableURLRequest *)request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
        [(NSMutableURLRequest *)request setValue:@" Safari/537.1" forHTTPHeaderField:@"User_Agent"];
    }
}
andrewsi
  • 10,807
  • 132
  • 35
  • 51
GannerMann
  • 31
  • 5
2

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).

Espen Riskedal
  • 1,425
  • 15
  • 28
  • It seems that start working again but now asks me to login regardless of the valid access token I'm adding to the request parameters, do you have any idea how to deal with that?? – Sahar Lepa Sep 29 '12 at 04:08