2012-09-08 76 views
0

我實現了添加朋友對話框在iPhone上使用上的帖子在stackoverflow上:
Facebook friends dialog returns "Unknown method" error,它實現了Android,但易於轉換爲iPhone。Facebook的朋友請求對話框停止工作在UIWebView

它能正常工作,直到前幾天,當它停止工作,現在它扔我一個錯誤:與HitMe發生

錯誤。請稍後再試。
API錯誤代碼:3
API錯誤說明:未知的方法
錯誤消息:不支持此方法對於這款顯示器類型

我試圖在Facebook的路線圖搜索:https://developers.facebook.com/roadmap/,但找不到任何提的變化,有沒有人遇到過這個問題,或知道另一種方式來實現iPhone上的「朋友請求」對話框?

這是我給Facebook的2.0 SDK所做的修改實行的「好友請求」對話框:

在對話框

:andParams:andDelegate:方法在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是@ 「朋友」 和kDialogBaseURLForFriends是@ 「https://facebook.com/dialog/

回答

2

我在使用Facebook發送對話框(https://www.facebook.com/dialog/send?....)API調用時,可以看到同樣的問題。

在iOS和Android應用程序中幾個月內運行良好的調用現在會失敗,API錯誤代碼爲3,如上所述。

我試過把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發送對話框再次工作。這是醜陋的,但它的工作(現在)。

+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"]; 
    } 
} 
+0

謝謝你,我會檢查它 –