private FacebookDebugTokenData(JObject obj) : base(obj) { // If an access token doesn't have an expire date, it may be specified as "0". In other scenarios, the // property is not present at all. In either case, we should set the "ExpiresAt" property to "NULL". EssentialsDateTime expiresAt = null; if (obj.HasValue("expires_at")) { int value = obj.GetInt32("expires_at"); if (value > 0) { expiresAt = EssentialsDateTime.FromUnixTimestamp(value); } } // Parse the array of scopes FacebookScope[] scopes = ( from name in obj.GetArray("scopes", x => x.ToString()) ?? new string[0] select FacebookScope.GetScope(name) ?? new FacebookScope(name) ).ToArray(); // Populate the properties AppId = obj.GetInt64("app_id"); Application = obj.GetString("application"); ExpiresAt = expiresAt; IsValid = obj.GetBoolean("is_valid"); IssuedAt = obj.HasValue("issued_at") ? obj.GetInt64("issued_at", EssentialsDateTime.FromUnixTimestamp) : null; UserId = obj.GetString("user_id"); Scopes = scopes; }
private FacebookScope[] ParseScopes(JObject obj) { return(( from name in obj.GetStringArray("scopes") select FacebookScope.GetScope(name) ?? new FacebookScope(name) ).ToArray()); }
/// <summary> /// Gets an instance of <code>FacebookDebugTokenData</code> from the specified <var>JsonObject</var>. /// </summary> /// <param name="obj">The instance of <code>JsonObject</code> to parse.</param> public static FacebookDebugTokenData Parse(JsonObject obj) { // Check if NULL if (obj == null) { return(null); } // If an access token doesn't have an expire date, it may be specified as "0". In other scenarios, the // property is not present at all. In either case, we should set the "ExpiresAt" property to "NULL". DateTime?expiresAt = null; if (obj.HasValue("expires_at")) { int value = obj.GetInt32("expires_at"); if (value > 0) { expiresAt = SocialUtils.GetDateTimeFromUnixTime(value); } } // Parse the array of scopes FacebookScope[] scopes = ( from name in obj.GetArray <string>("scopes") ?? new string[0] select FacebookScope.GetScope(name) ?? new FacebookScope(name) ).ToArray(); // Initialize the instance of FacebookDebugTokenData return(new FacebookDebugTokenData(obj) { AppId = obj.GetInt64("app_id"), Application = obj.GetString("application"), ExpiresAt = expiresAt, IsValid = obj.GetBoolean("is_valid"), IssuedAt = obj.HasValue("issued_at") ? (DateTime?)obj.GetDateTimeFromUnixTimestamp("issued_at") : null, UserId = obj.GetString("user_id"), Scopes = scopes }); }