本文整理汇总了C#中AccessToken.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# AccessToken.ToJson方法的具体用法?C# AccessToken.ToJson怎么用?C# AccessToken.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AccessToken
的用法示例。
在下文中一共展示了AccessToken.ToJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendSuccessResult
protected override void SendSuccessResult()
{
if (string.IsNullOrEmpty(this.accessToken))
{
this.SendErrorResult("Empty Access token string");
return;
}
// Make a Graph API call to get FBID
FB.API(
"/me?fields=id&access_token=" + this.accessToken,
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?access_token=" + this.accessToken,
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);
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));
}
});
});
}
示例2: SendSuccessResult
protected override void SendSuccessResult()
{
if (string.IsNullOrEmpty(this.accessToken))
{
this.SendErrorResult("Empty Access token string");
return;
}
var token = new AccessToken(
this.accessToken,
"MockUserId",
DateTime.Now.AddDays(60),
this.Permissions);
var result = (IDictionary<string, object>)MiniJSON.Json.Deserialize(token.ToJson());
if (!string.IsNullOrEmpty(this.CallbackID))
{
result[Constants.CallbackIdKey] = this.CallbackID;
}
if (this.Callback != null)
{
this.Callback(MiniJSON.Json.Serialize(result));
}
}