Last active
December 18, 2017 11:05
-
-
Save Lycheejam/bc47517de9320a5b0f92b98c6dce91f6 to your computer and use it in GitHub Desktop.
asp.net steamAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model WebApplication1.Models.SteamUser.SteamStats | |
<body> | |
<p>プレイヤーネーム:@Model.response.players[0].realname</p> | |
<p>アバター @Model.response.players[0].avatarfull</p> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
ViewBag.Title = "SteamAPI Form"; | |
} | |
<h2>Steam ID入力</h2> | |
<form action="/SteamAPI/getName" method="post"> | |
<div class="control-group"> | |
<label class="control-label" for="steamid">SteamID</label> | |
<div class="controls"> | |
<input class="text-box single-line" id="steamid" name="SteamID" type="text" value="" /> | |
<span class="field-validation-valid help-inline" data-valmsg-for="SteamID" data-valmsg-replace="true"></span> | |
</div> | |
</div> | |
<div class="form-actions no-color"> | |
<input type="submit" value="送信" class="btn" /> | |
</div> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Runtime.Serialization; | |
using System.Runtime.Serialization.Json; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace WebApplication1.Controllers | |
{ | |
public class SteamAPIController : Controller | |
{ | |
// GET: SteamAPI | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
public String getName(string steamid) | |
{ | |
try | |
{ | |
// URLエンコーディング | |
string url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=STEAM-API-KEY&steamids="; | |
// HTTPアクセス | |
WebRequest req = WebRequest.Create(url + steamid); | |
WebResponse res = req.GetResponse(); | |
// レスポンス(JSON)をオブジェクトに変換 | |
SteamStats sstats; | |
using (res) | |
{ | |
using (var resStream = res.GetResponseStream()) | |
{ | |
var serializer = new DataContractJsonSerializer(typeof(SteamStats)); | |
sstats = (SteamStats)serializer.ReadObject(resStream); | |
} | |
} | |
// 結果を出力 | |
return View(sstats); | |
} | |
catch (Exception) | |
{ | |
throw; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Serialization; | |
using System.Web; | |
namespace WebApplication1.Models | |
{ | |
public class SteamUser | |
{ | |
[DataContract] | |
public class SteamStats | |
{ | |
[DataMember] | |
public Response response { get; set; } | |
} | |
[DataContract] | |
public class Response | |
{ | |
[DataMember] | |
public List<Player> players { get; set; } | |
[DataContract] | |
public class Player | |
{ | |
[DataMember] | |
public string steamid { get; set; } | |
[DataMember] | |
public string communityvisibilitystate { get; set; } | |
[DataMember] | |
public string profilestate { get; set; } | |
[DataMember] | |
public string personaname { get; set; } | |
[DataMember] | |
public long lastlogoff { get; set; } | |
[DataMember] | |
public string profileurl { get; set; } | |
[DataMember] | |
public string avatar { get; set; } | |
[DataMember] | |
public string avatarmedium { get; set; } | |
[DataMember] | |
public string avatarfull { get; set; } | |
[DataMember] | |
public string personastate { get; set; } | |
[DataMember] | |
public string realname { get; set; } | |
[DataMember] | |
public string primaryclanid { get; set; } | |
[DataMember] | |
public long timecreated { get; set; } | |
[DataMember] | |
public int personastateflags { get; set; } | |
[DataMember] | |
public string loccountrycode { get; set; } | |
[DataMember] | |
public string locstatecode { get; set; } | |
[DataMember] | |
public int loccityid { get; set; } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment