Xamarin.Android检索Facebook个人资料错误

时间:2017-06-29 20:30:14

标签: c# android facebook xamarin.android xamarin.forms

我正在尝试使用此代码从Facebook获取用户信息:

                    auth.Completed += (sender, eventArgs) =>
                    {
                        if (eventArgs.IsAuthenticated)
                        {
                            OAuthConfig.User = new UserDetails();
                            // Get and Save User Details 
                            OAuthConfig.User.Token = eventArgs.Account.Properties["access_token"];//oauth_token"];
                            OAuthConfig.User.ExpiresIn = eventArgs.Account.Properties["expires_in"];

                            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=email,first_name,last_name,gender"), null, eventArgs.Account);
                            var response = request.GetResponseAsync();
                            var obj = JObject.Parse(response.GetResponseText());

                            var id = obj["id"].ToString().Replace("\"", "");
                            var name = obj["first_name"].ToString().Replace("\"", "");
                            var lastName = obj["last_name"].ToString().Replace("\"", "");
                            var email = obj["email"].ToString().Replace("\"", "");

                            //var user = ParseFacebookUtils.LogInAsync(id, accessToken, expiryDate);

                            OAuthConfig.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    };

但是,我在行(var obj = JObject.Parse(response.GetResponseText());)上收到此错误:

'Task<Response>' does not contain a definition for 'GetResponseText' ...  

我缺少什么参考?

1 个答案:

答案 0 :(得分:1)

使用await来获取结果而不是任务

var response = await request.GetResponseAsync();

您需要定义以下内容

auth.Completed += async (sender, eventArgs) =>