in Facebook.Unity/PlatformEditor/MockDialogs/MockLoginDialog.cs [54:146]
protected override void SendSuccessResult()
{
if (string.IsNullOrEmpty(this.accessToken))
{
this.SendErrorResult("Empty Access token string");
return;
}
// This whole module does a bunch of Graph API calls to simulate the
// reponse from an actual Login. It then constructs the Result Object to
// send over to the SDK to construct an AccessToken object. In order to honor
// the correct domain while doing this, we will construct a dummy access token so
// that FB.API() can determine the right domain to send the request to. Once this method
// returns the real AccessToken object will be constructed and will replace this dummy one.
List<string> dummyPerms = new List<string>();
dummyPerms.Add("public_profile");
string graphDomain = this.accessToken.StartsWith("GG") ? "gaming" : "facebook";
AccessToken tmpAccessToken = new AccessToken(
this.accessToken,
"me",
DateTime.UtcNow.AddDays(60),
dummyPerms,
DateTime.UtcNow,
graphDomain);
AccessToken.CurrentAccessToken = tmpAccessToken;
// Make a Graph API call to get FBID
FB.API(
"/me?fields=id",
HttpMethod.GET,
delegate(IGraphResult graphResult)
{
if (!string.IsNullOrEmpty(graphResult.Error))
{
this.SendErrorResult("Graph API error: " + graphResult.Error);
return;
}
string facebookID = graphResult.ResultDictionary["id"] as string;
// Make a Graph API call to get Permissions
FB.API(
"/me/permissions",
HttpMethod.GET,
delegate(IGraphResult permResult)
{
if (!string.IsNullOrEmpty(permResult.Error))
{
this.SendErrorResult("Graph API error: " + permResult.Error);
return;
}
// Parse permissions
List<string> grantedPerms = new List<string>();
List<string> declinedPerms = new List<string>();
var data = permResult.ResultDictionary["data"] as List<object>;
foreach (Dictionary<string, object> dict in data)
{
if (dict["status"] as string == "granted")
{
grantedPerms.Add(dict["permission"] as string);
}
else
{
declinedPerms.Add(dict["permission"] as string);
}
}
// Create Access Token
var newToken = new AccessToken(
this.accessToken,
facebookID,
DateTime.UtcNow.AddDays(60),
grantedPerms,
DateTime.UtcNow,
graphDomain);
var result = (IDictionary<string, object>)MiniJSON.Json.Deserialize(newToken.ToJson());
result.Add("granted_permissions", grantedPerms);
result.Add("declined_permissions", declinedPerms);
if (!string.IsNullOrEmpty(this.CallbackID))
{
result[Constants.CallbackIdKey] = this.CallbackID;
}
if (this.Callback != null)
{
this.Callback(new ResultContainer(result));
}
});
});
}