我想从蒸汽中得到侧写信息。所以首先我修正了我可以通过蒸汽登录,我使用了下面的教程:http://www.oauthforaspnet.com/providers/steam/
但是,现在我希望从登录的用户那里获得蒸汽配置文件id,这样我就可以使用来自蒸汽API的JSON从用户那里获取信息。
https://steamcommunity.com/profiles/(this
我希望有人能帮我,我已经找了好几个小时了,但没有结果。
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);发布于 2016-01-07 22:50:51
不久前,我们发现了答案:
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.)我们发现蒸汽在数据库表中保存了一个名为'AspNetUserLogins‘的用户蒸汽id,该表中的提供键是一个由更多的部分组成的url。例如:
http://steamcommunity.com/openid/id/here-users-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;
}请注意,您必须在url中添加步骤1中的蒸汽密钥。
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>https://stackoverflow.com/questions/33475737
复制相似问题