簡體   English   中英

Facebook iOS SDK用戶配置文件登錄屬性

[英]Facebook iOS SDK User Profile Login Attributes

我已經將我的項目配置為使用Facebook SDK登錄。我正在使用以下框架:

FBSDKShareKit
FBSDKLoginKit
FBSDKCoreKit

我在一個快速的項目中使用了它,因此我添加了橋接頭,將所有框架導入到頭,並在Facebook開發者網站上注冊該項目后,使用應用程序ID正確配置了屬性列表。 我還在AppDelegate方法中添加了必要的代碼。

我的登錄代碼如下所示:

if(FBSDKAccessToken.currentAccessToken() != nil)   {
            returnUserData()
        }

        else{


            let loginView  = FBSDKLoginButton()
            loginView.center = view.center
            loginView.readPermissions = ["public_profile", "email", "user_friends"]
            loginView.delegate = self
            view.addSubview(loginView)
        }

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        if ((error) != nil){
            //Process error
            println(error.localizedDescription)
        }

        else if result.isCancelled{
            //Handle cancellations
        }

        else{

            println(result.token.description)
            //If you ask for multiple permissions you should check if
            //specific permissions are missings.
            if result.grantedPermissions.contains("email"){
                returnUserData()
            }
        }
    }

   func returnUserData (){

        let graphRequest  = FBSDKGraphRequest(graphPath: "me", parameters: nil)

        graphRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
            if ((error) != nil)
            {
                // Process error
                println("Error: \(error)")
            }
            else
            {
                let id : String = result.valueForKey("id") as! String
                self.getUserProfileWithId(id)
                let userName : NSString = result.valueForKey("name") as! String
            }
        }
    }    

https://developers.facebook.com/docs/facebook-login/permissions/v2.4

上面的鏈接是我要獲得的權限所參考的文檔。 但是,當我運行請求時,我只會從調用中收到"id""name"屬性。

該文檔指出public_profile(默認)應具有

*id
*name
*first_name
*last_name
*age_range
*link
*gender
*local
*timezone
*updated_time
*verified

但是,我從未收到這些屬性,並且已經確認使用此代碼具有對公共配置文件的授予權限。

 if result.grantedPermissions.contains("public_profile"){
                println("Permissions valid for profile")
            }

我還更改了我的facebook帳戶的設置,以便可以搜索並且沒有任何限制,但這似乎也沒有作用。 我嘗試了一個朋友的帳戶,結果是一樣的,只是id和name字段是從登錄調用返回的。 關於如何獲取完整的public_profile信息的任何幫助都將非常棒

使用v2.4,您必須在fields參數的列表中請求要接收的每個字段:

為了嘗試改善移動網絡上的性能,v2.4中的“節點和邊緣”要求您顯式請求GET請求所需的字段。 例如,默認情況下,GET /v2.4/me/feed不再包含喜歡和評論,但是GET /v2.4/me/feed?fields=comments,喜歡將返回數據。 有關更多詳細信息,請參閱有關如何請求特定字段的文檔。

暫無
暫無

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

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