2014-04-17 46 views
2

我讀了Facebook文檔並實現了我的代碼,但請求沒有發送。我無法在網站上看到請求通知。我可以在我的日誌屏幕上看到請求ID。通過應用程序發送Facebook請求

這裏是我的部分代碼: 我從developer.facebook.com

+ (NSDictionary*)parseURLParams:(NSString *)query { 
NSArray *pairs = [query componentsSeparatedByString:@"&"]; 
NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
for (NSString *pair in pairs) { 
    NSArray *kv = [pair componentsSeparatedByString:@"="]; 
    NSString *val = 
    [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    params[kv[0]] = val; 
} 
return params; 
} 

+(void) requestFriendMethod{ 

// Display the requests dialog 
[FBWebDialogs 
presentRequestsDialogModallyWithSession:nil 
message:@"message" 
title:@"title" 
parameters:nil 
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
    if (error) { 
     // Error launching the dialog or sending the request. 
     NSLog(@"Error sending request."); 
    } else { 
     if (result == FBWebDialogResultDialogNotCompleted) { 
      // User clicked the "x" icon 
      NSLog(@"User canceled request."); 
     } else { 
      // Handle the send request callback 
      NSDictionary *urlParams = [AKFacebook parseURLParams:[resultURL query]]; 
      if (![urlParams valueForKey:@"request"]) { 
       // User clicked the Cancel button 
       NSLog(@"User canceled request."); 
      } else { 
       // User clicked the Send button 
       NSString *requestID = [urlParams valueForKey:@"request"]; 
       NSLog(@"Request ID: %@", requestID); 
      } 
     } 
    } 
}]; 

} 

我在做什麼錯誤代碼?感謝您的回答和建議。

回答

0

確保您的Facebook應用ID在開發者頁面和xcode中的信息相同,然後啓用沙箱模式,並且必須在開發者頁面中填充畫布網址[在Facebook類別下的應用]。

NSString *facebookID = @"Your friend facebook id"; 
    NSMutableDictionary* params = 
    [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"]; 

    NSString *message = @"SOME_MESSAGE"; 
    NSString *title = @"TITLE"; 

    [FBWebDialogs presentRequestsDialogModallyWithSession:nil 
        message:message 
       title:title 
       parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
         if (error) 
        { 
        // Case A: Error launching the dialog or sending request. 
         NSLog(@"Error sending request."); 
        } 
        else 
        { 
         if (result == FBWebDialogResultDialogNotCompleted) 
        { 
        // Case B: User clicked the "x" icon 
         NSLog(@"User canceled request."); 
        } 
        else 
        { 
         NSLog(@"Request Sent. %@", params); 
        } 
     }}]; 
+0

我已經嘗試過此代碼,但它也不發送請求。也許正如你所說,它可以是沙箱模式。感謝您的回答 –

+0

雅,請檢查沙箱模式。如果我的答案可以幫助你,upvote和接受。 – Ramdy

相關問題