Facebook好友请求对话框停止在UIWebView上工作

时间:2012-09-08 20:01:09

标签: ios facebook

我使用stackoverflow上的帖子在iPhone上实现了添加好友对话框:
Facebook friends dialog returns "Unknown method" error,它是针对Android实现的,但很容易转换为iPhone。

它工作正常,直到几天前它停止工作,现在它给我一个错误:

HitMe发生错误。请稍后再试。
API错误代码:3
API错误说明:未知方法
错误消息:此显示类型

不支持此方法

我尝试在facebook路线图中搜索:https://developers.facebook.com/roadmap/但是找不到任何改变,有没有人遇到过这个问题,或者知道在iPhone上实现“朋友请求”对话框的另一种方式?

这是我对Facebook 2.0 sdk所做的更改,以实现“朋友请求”对话框:

在对话框中的

:andParams:andDlegate:Facebook.m中的方法我用以下代码替换了原始代码:

-(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];

}

其中kFriends是@“friends”而kDialogBaseURLForFriends是@“https://facebook.com/dialog/

2 个答案:

答案 0 :(得分:3)

它适用于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"];
    }
}

答案 1 :(得分:2)

我在使用Facebook发送对话框(https://www.facebook.com/dialog/send?....)API调用时遇到同样的问题。

iOS和Android应用程序中运行良好数月的调用现在因API错误代码而失败:如上所述。

我已经尝试完全忽略display = iframe,或者更改为其他显示类型,如弹出窗口等。它仍然无法正常工作。 http://developers.facebook.com/docs/reference/dialogs/上的文档仍然提到iOS和Android是这些类型对话框的有效用例。在桌面浏览器中试用相同的URL可以正常工作。

更新:找到适用于Android的解决方法。只需更改webview容器的useragent:

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");

这至少让Android上的Send Dialog再次运行。这很丑陋,但现在有效。