本文整理匯總了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));
}
}