如何从 facebook access_token 获取用户电子邮件 public_profile

How to get user email, public_profile from facebook access_token

我正在构建一个 windows phone 8.1 应用程序,允许用户登录 facebook 帐户。

有我的代码:

string productId = "myproductid";

string facebookAppId = "myfacebookappid";
string redirectUri = "msft-"+productId+"://authorize";
string scope = "public_profile,email"; // What you want to fetch from the facebook user
string responseType = "token"; // Other response types possible

UriBuilder authUri = new UriBuilder("https://www.facebook.com/dialog/oauth");
authUri.Query = "client_id=" + facebookAppId + "&redirect_uri=" + redirectUri + "&scope=" + scope + "&response_type=" + responseType;

var success = await Windows.System.Launcher.LaunchUriAsync(uriToLaunch);

和 App.xaml.cs 中的代码:

    protected override void OnActivated(IActivatedEventArgs args)
    {
        base.OnActivated(args);


        if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
        {
            App.MobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
        }
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;

            WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(eventArgs.Uri.Fragment);

            string fbAccessToken = decoder.GetFirstValueByName("#access_token");

            /* Now you can use the access token to interact with the Facebook API */
        }

    }

但是如何从 "fbAccessToken" 获取用户的电子邮件和个人资料?

谢谢。

您可以使用 facebook 的图形 API

graph.facebook.com/me?access_token={0}

请参考这个 link - https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3

添加scope/Extended获取用户资料等权限,

string scope ="user_about_me,read_stream,publish_actions,user_birthday,offline_access,email"