2016-02-13 38 views
0

用戶使用Facebook註冊後,我想檢索一些關於Facebook用戶的更多信息。但是,我只能得到id和姓名,而顯然電子郵件返回nil。這是我的代碼:Facebook圖表請求無法檢索iOS 9.2中的電子郵件 - xCode 7

import Foundation 
import UIKit 
import Parse 
import MessageUI 
import QuartzCore 
import ParseFacebookUtilsV4 
import FBSDKCoreKit 
import Bolts 
import FBSDKLoginKit 

class FacebookCompleteSignUpController: UIViewController, UITextFieldDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, email, first_name, last_name"]) 
     graphRequest.startWithCompletionHandler({ 
      (connection, result, error) -> Void in 

      if error != nil { 
       print(error) 

      } else if let result = result { 
       print(result["first_name"]) 
       print(result["email"]) 

       do { 
        try PFUser.currentUser()?.save() 
       } catch let ex { 
        print(ex) 
       } 
      } 
     }) 
    } 
} 

如果有人知道如何解決這個問題,如果你能讓我知道,這將是非常好的。 謝謝。

回答

0

下面可能是一個原因:

email 

Provides access to the person's primary email address via the email property on the user object. 

Do not spam users. Your use of email must comply with both Facebook policies and with the CAN-SPAM Act. 

Note, even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty. 

Review 
Your app may use this permission without review from Facebook. 

請嘗試用圖形API資源管理器來訪問相同的信息,看看你所得到的用戶的電子郵件ID:https://developers.facebook.com/tools/explorer/

+0

我不能讓它從圖形API。它報告的錯誤是: 只有在用戶授予「電子郵件」權限後,用戶對象才能訪問「電子郵件」字段。 –

+0

即使在我的Facebook應用程序評論中,它說我有權限:[截圖](http://s12.postimg.org/j5yhdgoql/Screen_Shot_2016_02_13_at_12_37_48_AM.png) –

+0

@GiulioColleluori:這就是我評論中的第三行說 - 用戶可以決定是否公開他的電子郵件。如果用戶決定不共享電子郵件,您將不會收到它。如果電子郵件對您的應用程序是必需的,那麼您必須再次用另一個窗口提示用戶輸入電子郵件。這是我們爲我們的應用程序實施它的方式。您必須將電子郵件ID映射到您從facebook處收到的user_id。 – BinojVJ

相關問題