Esempio n. 1
0
		private Task<FacebookUser> getUserData(Facebook.CoreKit.AccessToken token)
		{
			var fbUser = new FacebookUser()
				{
					Token = token.TokenString,
					ExpiryDate = token.ExpirationDate.ToDateTime()
				};

			var completion = new TaskCompletionSource<FacebookUser>();

			var request = new GraphRequest("me", NSDictionary.FromObjectAndKey(new NSString("id, first_name, last_name, email, location"), new NSString("fields")), "GET");
			request.Start((connection, result, error) =>
				{					
					if(error != null)
					{
						Mvx.Trace(MvxTraceLevel.Error, error.ToString());
					}
					else
					{
						
						var data = NSJsonSerialization.Serialize(result as NSDictionary, 0, out error);
						if(error != null)
						{
							Mvx.Trace(MvxTraceLevel.Error, error.ToString());
						}
						else
						{
							var json = new NSString(data, NSStringEncoding.UTF8).ToString();
							fbUser.User = JsonConvert.DeserializeObject<User>(json);
							fbUser.User.ProfilePictureUrl =  string.Format("https://graph.facebook.com/{0}/picture?width={1}&height={1}", fbUser.User.ID, Constants.FBProfilePicSize);
						}
						completion.TrySetResult(fbUser);	
					}

				});
			return completion.Task;
		}
Esempio n. 2
0
		private Task<FacebookUser> getUserData(Xamarin.Facebook.AccessToken token)
		{
			var fbUser = new FacebookUser()
				{
					Token = token.Token,
					ExpiryDate = token.Expires.ToDateTime()
				};

			var completion = new TaskCompletionSource<FacebookUser>();
			var callback = new GraphRequestCallback(completion, fbUser);
			var request = GraphRequest.NewMeRequest(token, callback);
			Bundle parameters = new Bundle();
			parameters.PutString("fields", "id, first_name, last_name, email");
			request.Parameters = parameters;
			request.ExecuteAsync();
			return completion.Task;
		}
Esempio n. 3
0
			public GraphRequestCallback(TaskCompletionSource<FacebookUser> completion, FacebookUser initialToken)
			{
				_completion = completion;
				_initialToken = initialToken;
			}