前一段時間,我們發現了答案:
1)插入你從教程這裏的關鍵:
var options = new SteamAuthenticationOptions
{
ApplicationKey = "Your API Key",
Provider = new OpenIDAuthenticationProvider // Steam is based on OpenID
{
OnAuthenticated = async context =>
{
// Retrieve the user's identity with info like username and steam id in Claims property
var identity = context.Identity;
}
}
};
app.UseSteamAuthentication(options);
2)我們發現,蒸汽,節約了用戶的蒸汽ID在名爲「AspNetUserLogins」的數據庫表中,該表內的providerkey是由更多部分組成的url。例如:
http://steamcommunity.com/openid/id/here-users-steamid
我們只需要用戶steamid,所以我們要分開,在步驟3
3)做一個控制器,例如:SteamController。在這裏,我們將添加一個公共字符串:
public string GetSteamID()
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new Steam.Models.ApplicationDbContext()));
var CurrentUser = manager.FindById(User.Identity.GetUserId());
if (User.Identity.Name != "")
{
string url = CurrentUser.Logins.First().ProviderKey;
ViewBag.steamid = url.Split('/')[5]; //here we going to split the providerkey so we get the right part
}
else
{
ViewBag.steamid = "";
}
return ViewBag.steamid;
}
)現在我們可以添加一些東西,讓我們說,我們要添加的個人資料信息。轉到您的SteamController並添加:
[HttpGet]
public ContentResult GetProfile()
{
string url = string.Format("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=addyourkeyhere&steamids={0}", this.GetSteamID());
string result = null;
using (var client = new WebClient())
{
result = client.DownloadString(url);
}
return Content(result, "application/json");
}
通知,你必須從URL步驟1中添加蒸汽關鍵。
- )製作一個名爲profile.js的腳本。這裏我們要添加我們的個人資料信息。
function profilepic() {
$.ajax({
url: 'http://localhost:3365/steam/GetProfile',
dataType: 'json',
success: function (data) {
$.each(data.response.players, function (key, value) {
if ($('.profile')) {
$('.profile').append("<img src='" + value.avatar + "'> <span>" + value.personaname + "</span>")
}
if ($('.profile1')) {
$('.profile1').append("<img src='" + value.avatarfull + "'>")
}
if ($('.username')) {
$('.username').append(value.personaname)
}
console.log(value)
});
}, error: function (httpReq, status, exception) {
console.log(status + " " + exception);
}
});
}
6.)現在我們要做的最後一步,產生具有類的視圖,例如:
<div class="userprofile">
<span class="profile1"></span>
<div class="userdescription">
<h2 class="username"></h2>
</div>
</div>
- )我希望這會幫助一些人,爲更多的問題,隨時問!