首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DotNetOpenAuth和Hotmail登录

DotNetOpenAuth和Hotmail登录
EN

Stack Overflow用户
提问于 2012-06-13 17:11:14
回答 1查看 765关注 0票数 1

如何使用DotNetOpenAuth检索Hotmail的登录电子邮件id

我已经从示例中尝试了这个代码,它给出了名称,而不是电子邮件id

代码语言:javascript
复制
IAuthorizationState authorization = client1.ProcessUserAuthorization(null);
    if (authorization == null)
    {
        // Kick off authorization request
        client1.RequestUserAuthorization(new[] { WindowsLiveClient.Scopes.Basic, "wl.emails" }, new Uri("http://localhost/SignIn.aspx")); // this scope isn't even required just to log in
    }
    else
    {
        var request = WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
        using (var response = request.GetResponse())
        {
            using (var responseStream = response.GetResponseStream())
            {
                var graph = WindowsLiveGraph.Deserialize(responseStream);
                //this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2012-06-21 18:52:18

您需要将另一个项目添加到Scope类中

代码语言:javascript
复制
/// <summary>
/// Well-known scopes defined by the Windows Live service.
/// </summary>
/// <remarks>
/// This sample includes just a few scopes.  For a complete list of scopes please refer to:
/// http://msdn.microsoft.com/en-us/library/hh243646.aspx
/// </remarks>
public static class Scopes
{
    /// <summary>
    /// The ability of an app to read and update a user's info at any time. Without this scope, an app can access the user's info only while the user is signed in to Live Connect and is using your app.
    /// </summary>
    public const string OfflineAccess = "wl.offline_access";

    /// <summary>
    /// Single sign-in behavior. With single sign-in, users who are already signed in to Live Connect are also signed in to your website.
    /// </summary>
    public const string SignIn = "wl.signin";

    /// <summary>
    /// Read access to a user's basic profile info. Also enables read access to a user's list of contacts.
    /// </summary>
    public const string Basic = "wl.basic";

    /// <summary>
    /// Read access to a user's personal, preferred, and business email addresses.
    /// </summary>
    public const string Email = "wl.emails";
}

然后,您可以使用以下代码传入正确的作用域-从示例中可以看到,您可以传入两个或多个作用域。您可以找到here提供的作用域的详细信息。

代码语言:javascript
复制
var windowsiveClient = WindowsLiveClient.Instance();

var authorization = windowsiveClient.ProcessUserAuthorization();
if (authorization == null)
{
    // Kick off authorization request
    windowsiveClient.RequestUserAuthorization(scope: new[] { WindowsLiveClient.Scopes.Email, WindowsLiveClient.Scopes.Basic });

    // retuning null will force the page to redirect to Windows Live and as we have not specified a callback if authorized will
    // return back to the calling URL - in this instance the 'AttemptSignInForWindowLiveOpenId' controller action.
    return null; // 
}

WindowsLiveGraph windowsLiveModel;

var windowsLiveRequest = WebRequest.Create(string.Format("https://apis.live.net/v5.0/me?access_token={0}", Uri.EscapeDataString(authorization.AccessToken)));
using (var response = windowsLiveRequest.GetResponse())
{
    using (var responseStream = response.GetResponseStream())
    {
        windowsLiveModel = WindowsLiveGraph.Deserialize(responseStream);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11011642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档