[MobileAppController] [Authorize] public class FacebookController : ApiControlle private TodoUserService todoUserService; protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); todoUserService = new TodoUserService(); } public async Task<TodoUser> Get() { var creds = await this.User.GetAppServiceIdentityAsync<FacebookCredentials>(this.Request); return await todoUserService.GetFacebookUserInfoAsync(creds.AccessToken); } }
public async Task<TodoUser> GetFacebookUserInfoAsync(string accessToken) { TodoUser info = new TodoUser(); try { using (var client = new HttpClient()) { var response = await client.GetAsync("https://graph.facebook.com/me " + "?access_token=" + accessToken + "&fields=name,picuture,first_name,last_name,id"); var o = JObject.Parse(await response.Content.ReadAsStringAsync()); info.Name = o["name"].ToString(); info.ProfilePicture = (o["data"]["url"].ToString()); info.FacebookId = o["id"].ToString(); info.FirstName = o["first_name"].ToString(); info.LastName = o["last_name"].ToString(); } } catch (Exception ex) { info.Name = ex.Message + "\n" + ex.StackTrace; } return info; }
Object reference not set to an instance of an object
client.GetAsync("url")
"at MyExpenditureService.Services.TodoUserService.<GetFacebookUserInfoAsync>d__0.MoveNext()" Any idea how to fix this?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)