簡體   English   中英

Unity:通過Facebook SDK獲取Facebook電子郵件

[英]Unity : Get Facebook email by Facebook SDK

我使用Facebook SDK進行我的應用登錄,並嘗試訪問ID,名稱和電子郵件。 我遵循來自Facebook開發人員FB.LogInWithReadPermissions的參考

public void FBLogin(){
    FB.LogInWithReadPermissions (new List<string>(){"public_profile","email","user_friends"}, AuthCallback);
}

private void AuthCallback (ILoginResult result) {
    if (FB.IsLoggedIn) {
        // AccessToken class will have session details
        var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
        // Print current access token's User ID

        // Print current access token's granted permissions
        foreach (string perm in aToken.Permissions) {
            Debug.Log(perm);
        }
        FB.API ("/me?fields=id,name,email",HttpMethod.GET, GetFacebookInfo);
    } else {
        Debug.Log("User cancelled login");
    }
}

public void GetFacebookInfo(IResult result){
    if (result.Error == null) {
        Debug.Log (result.ResultDictionary ["id"].ToString ());
        Debug.Log (result.ResultDictionary ["name"].ToString ());
        Debug.Log (result.ResultDictionary ["email"].ToString ());
    } else {
        Debug.Log (result.Error);
    }
}

我在Debug.Log (result.ResultDictionary ["email"].ToString ());得到錯誤Debug.Log (result.ResultDictionary ["email"].ToString ());

KeyNotFoundException: The given key was not present in the dictionary.

我錯過了什么 ? 如何獲得電子郵件。 非常感謝。

嘗試換線

    FB.API ("/me?fields=id,name,email",HttpMethod.GET, GetFacebookInfo);

        FB.API ("/me?fields=id,name,email", HttpMethod.GET, GetFacebookInfo, new Dictionary<string, string> () { });

我記得有同樣的錯誤,它為我工作。

如果您使用的是測試用戶,則必須向測試用戶添加“電子郵件”權限。

轉到“開發人員facebook”並選擇您的應用(“ Wizard's Run”對我而言):

在此處輸入圖片說明

然后轉到“測試用戶”

在此處輸入圖片說明

然后轉到您要測試的用戶,然后選擇“更改此測試用戶授予應用程序的權限”

在此處輸入圖片說明

如果尚未列出“電子郵件”,則輸入“電子郵件”並更新。

在此處輸入圖片說明

暫無
暫無

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

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