2015-04-01 206 views
0

我正在构建一个允许用户登录Facebook帐户的Windows Phone 8.1应用程序。如何从facebook获取用户电子邮件,public_profile access_token

有我的代码:

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

谢谢。

+0

https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3 – Tobi 2015-04-01 08:15:43

回答

-1

添加范围/扩展权限来获得用户配置文件等,

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

他只是想在问题中提到'public_profile'和'email'! – Tobi 2015-04-01 12:52:36

+0

这将有助于未来的其他人..这就是为什么我添加我知道的所有权限。 – Vijay 2015-04-01 16:32:55

相关问题