簡體   English   中英

如何在iOS中獲取Facebook用戶朋友的電子郵件ID

[英]How to fetch facebook user friends email ids in ios

我在我的應用程序中使用facebook graph api。 我想在我的應用程序fb圖用戶的表視圖中獲取fb朋友的電子郵件ID,但該用戶未提供電子郵件的任何屬性。 我怎樣才能對我有幫助-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {self.userInfoTextView.hidden = NO;

// Fetch user data
[FBRequestConnection
 startForMeWithCompletionHandler:^(FBRequestConnection *connection,
                                   id<FBGraphUser> user,
                                   NSError *error) {
     if (!error) {
         NSString *userInfo = @"";

         // Example: typed access (name)
         // - no special permissions required
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Name: %@\n\n",
                      user.name]];

         // Example: typed access, (birthday)
         // - requires user_birthday permission
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Birthday: %@\n\n",
                      user.birthday]];

         // Example: partially typed access, to location field,
         // name key (location)
         // - requires user_location permission
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Location: %@\n\n",
                      user.location[@"name"]]];



         // Example: access via key (locale)
         // - no special permissions required
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Locale: %@\n\n",
                      user[@"locale"]]];


         // Example: access via key for array (languages)
         // - requires user_likes permission
         if (user[@"languages"]) {
             NSArray *languages = user[@"languages"];
             NSMutableArray *languageNames = [[NSMutableArray alloc] init];
             for (int i = 0; i < [languages count]; i++) {
                 languageNames[i] = languages[i][@"name"];
             }
             userInfo = [userInfo
                         stringByAppendingString:
                         [NSString stringWithFormat:@"Languages: %@\n\n",
                          languageNames]];
         }
                      // Display the user info
         self.userInfoTextView.text = userInfo;
     }
 }];

}

您無法通過Facebook API獲得朋友的電子郵件地址(有充分的理由-防止垃圾郵件)。 您可以獲取當前用戶的電子郵件地址,但只能獲得擴展許可( 有關更多信息,請參見此處 )。

將此行添加到您的代碼。 希望對您有幫助。

NSLog(@"%@",[user objectForKey:@"email"]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM