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

时间:2015-04-01 08:01:50

标签: facebook windows-phone-8

我正在构建一个允许用户登录Facebook帐户的Windows Phone 8.1应用程序。

有我的代码:

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”获取用户的电子邮件和个人资料?

感谢。

2 个答案:

答案 0 :(得分:1)

您可以使用facebook的图形API

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

请参阅此链接 - https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3

答案 1 :(得分:-1)

添加范围/扩展权限以获取用户个人资料等,

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