当前位置: 首页>>代码示例>>C#>>正文


C# FacebookClient.GetTaskAsync方法代码示例

本文整理汇总了C#中Facebook.FacebookClient.GetTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.GetTaskAsync方法的具体用法?C# FacebookClient.GetTaskAsync怎么用?C# FacebookClient.GetTaskAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facebook.FacebookClient的用法示例。


在下文中一共展示了FacebookClient.GetTaskAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GrantCustomExtension

        public override async System.Threading.Tasks.Task GrantCustomExtension(OAuthGrantCustomExtensionContext context)
        {
            if(context.GrantType.ToLower() == "facebook")
            {
                var fbClient = new FacebookClient(context.Parameters.Get("accesstoken"));
                dynamic mainDataResponse = await fbClient.GetTaskAsync("me", new { fields = "first_name, last_name, picture" });
                dynamic friendListResponse = await fbClient.GetTaskAsync("me/friends");
                var friendsResult = (IDictionary<string, object>)friendListResponse;
                var friendsData = (IEnumerable<object>)friendsResult["data"];
                var friendsIdList = new List<string>();
                foreach (var item in friendsData)
                {
                    var friend = (IDictionary<string, object>)item;
                    friendsIdList.Add((string)friend["id"]);
                }
                User user = await CreateOrUpdateUser(mainDataResponse.id, mainDataResponse.first_name, mainDataResponse.last_name, mainDataResponse.picture.data.url, friendsIdList);
                
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(_fbIdKey, mainDataResponse.id));
                identity.AddClaim(new Claim(_idKey, user.Id.ToString()));

                await base.GrantCustomExtension(context);
                context.Validated(identity);
            }
            return;
        }
开发者ID:Mike-Wazowski,项目名称:AgileAPI,代码行数:26,代码来源:AuthTokenProvider.cs

示例2: Index

        // GET: Facebook
        public async Task<ActionResult> Index()
        {
            var access_token = HttpContext.Items["access_token"].ToString();
            if(access_token != null)
            {
                try
                {
                    var appsecret_proof = access_token.GenerateAppSecretProof();

                    var fb = new FacebookClient(access_token);
                    //Get current user's profile
                    dynamic myInfo =
                        await fb.GetTaskAsync("me?fields=first_name,last_name,link,locale,email,name,birthday,gender,location,bio,age_range".GraphAPICall(appsecret_proof));

                    //var facebookProfile = DynamicExtension.ToStatic<FacebookProfileViewModel>(myInfo);

                    //get curent profile
                    dynamic profileImgResult =
                        await fb.GetTaskAsync("{0}/picture?width=200&height=200&redirect=false".GraphAPICall((string)myInfo.id, appsecret_proof));
                    //facebookProfile.ImageUrl = profileImgResult.data.url;
                    var facebookProfile = new FacebookProfileViewModel()
                    {
                        
                    }
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
        }
开发者ID:tambama,项目名称:PenielSocialManager,代码行数:33,代码来源:FacebookController.cs

示例3: ContinueWithWebAuthenticationBroker

        public async void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args)
        {
            ObjFBHelper.ContinueAuthentication(args);
            if (ObjFBHelper.AccessToken != null)
            {
                fbclient = new Facebook.FacebookClient(ObjFBHelper.AccessToken);

                //Fetch facebook UserProfile:
                dynamic result = await fbclient.GetTaskAsync("me");
                string id = result.id;
                string email = result.email;
                string FBName = result.name;

                IsLoggedIn = true;
                btnFBLogin.Content = "Log out";
                txtBlockContent.Text = "You're now logged in as " + FBName;

                var msgDialog = new MessageDialog("Hello, " + FBName, "Login successful");
                await msgDialog.ShowAsync();
            }
            else
            {
                var msgDialog = new MessageDialog("Check your credentials and try again", "Login failed");
                await msgDialog.ShowAsync();
            }
        }
开发者ID:goldenskygiang,项目名称:NANConfessionClient,代码行数:26,代码来源:SettingsPage.xaml.cs

示例4: ProcessFbOathResult

        public int ProcessFbOathResult(FacebookOAuthResult oauthResult)
        {
            var resultCode = 0;
            var accessToken = oauthResult.AccessToken;
            App.ViewModel.UserPreference.AccessKey = accessToken;
            var fbS = new FacebookClient(accessToken);

            fbS.GetCompleted += (o, res) =>
                                    {
                                        if (res.Error != null)
                                        {
                                            resultCode = 1;
                                            return;
                                        }

                                        var result = (IDictionary<string, object>) res.GetResultData();
                                        App.ViewModel.UserPreference.FbUserId = (string) result["id"];
                                        App.ViewModel.UserPreference.Name = (string) result["name"];
                                        App.ViewModel.LoadData(true);
                                        App.ViewModel.SaveSettings();
                                        Dispatcher.BeginInvoke(() =>
                                                                   {
                                                                       facebookImage.Source =
                                                                           App.ViewModel.UserPreference.UserImage;
                                                                       name.Text = App.ViewModel.UserPreference.Name;
                                                                   });
                                    };

            fbS.GetTaskAsync("me");
            return resultCode;
        }
开发者ID:rubensworks,项目名称:hydra,代码行数:31,代码来源:Settings.xaml.cs

示例5: GetLogedUserInfoAsync

        /// <summary>
        /// Get the loged in user info based on the access token
        /// </summary>
        /// <param name="accessToken">Login returned access token</param>
        /// <returns>a dictionary with the user info values.</returns>
        public async Task<IDictionary<string, object>> GetLogedUserInfoAsync(string accessToken)
        {
            _fb = new FacebookClient(accessToken);

            return (IDictionary<string, object>)await _fb.GetTaskAsync("me");

        }
开发者ID:garymedina,项目名称:MyEvents,代码行数:12,代码来源:FacebookApi.cs

示例6: GrantCustomExtension

        public override async Task GrantCustomExtension(OAuthGrantCustomExtensionContext context)
        {
            if (context.GrantType.ToLower() == "facebook")
            {
                var fbClient = new FacebookClient(context.Parameters.Get("accesstoken"));

                dynamic response = await fbClient.GetTaskAsync("me", new { fields = "email, first_name, last_name" });
                
                string id = response.id;
                string email = response.email;
                string firstname = response.first_name;
                string lastname = response.last_name;
                // place your own logic to lookup and/or create users....

                // your choice of claims...
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("sub", $"{firstname} {lastname}"));
                identity.AddClaim(new Claim("role", id));

                await base.GrantCustomExtension(context);
                context.Validated(identity);

            }            
            return;
        }
开发者ID:rasmuschristensen,项目名称:SimpleOAuth,代码行数:25,代码来源:SimpleAuthTokenProvider.cs

示例7: LoadFacebookData

        private void LoadFacebookData()
        {
            var fb = new FacebookClient(App.FacebookAccessToken);
            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {

                }

                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                    {
                        var profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", App.FacebookId, "square", App.FacebookAccessToken);

                        ProfilePicture.Source = new BitmapImage(new Uri(profilePictureUrl));
                        FirstNameBox.Text = result["first_name"].ToString();
                        LastNameBox.Text = result["last_name"].ToString();
                        if (result["gender"].ToString().ToLower() == "male")
                            GenderPicker.SelectedIndex = 1;

                        var location = (IDictionary<string, object>)result["location"];
                        LocationBox.Text = location["name"].ToString();
                        //var favoriteteams = (List<IDictionary<string, object>>)result["favorite_teams"];
                    }

                    );
            };

            fb.GetTaskAsync("me");
        }
开发者ID:jeffblankenburg,项目名称:FanaticApp,代码行数:32,代码来源:Register.xaml.cs

示例8: Setup

        /// <summary>
        /// Setups the application link.
        /// </summary>
        public static void Setup()
        {
            _app = new FacebookClient();
            _app.AppId = "223453524434397";
            _app.AppSecret = "3b6769b53e52b0d122d2572950d770bd";

            dynamic parameters = new ExpandoObject();
            parameters.client_id = _app.AppId;
            parameters.client_secret = _app.AppSecret;
            parameters.grant_type = "client_credentials";

            Task<Object> connect = _app.GetTaskAsync("https://graph.facebook.com/oauth/access_token", parameters);
            connect.ContinueWith(task => {
                try
                {
                    // Save the access token
                    _app.AccessToken = JObject.Parse(task.Result.ToString()).Value<String>("access_token");
                    Connection |= FacebookState.Connected;
                }
                catch (AggregateException aex)
                {
                    aex.Handle(e =>
                    {
                        if (e is FacebookOAuthException)
                        {

                        }

                        return true;
                    });
                }
            });
        }
开发者ID:SleeplessByte,项目名称:playwithyourpeas,代码行数:36,代码来源:SocialController.cs

示例9: GetExtendedToken

        private async Task GetExtendedToken()
        {
            try
            {
                var accessToken = settings.Get<string>(FACEBOOK_TOKEN_SETTING);
                if (!string.IsNullOrEmpty(accessToken))
                {
                    var facebookClient = new FacebookClient(accessToken);
                    dynamic parameters = new ExpandoObject();
                    parameters.client_id = APP_ID;
                    parameters.client_secret = APP_SECRET;
                    parameters.grant_type = "fb_exchange_token";
                    parameters.fb_exchange_token = accessToken;
                    //parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";

                    dynamic tokenResponse = await facebookClient.GetTaskAsync("oauth/access_token",parameters);
                    if (!string.IsNullOrEmpty(tokenResponse.access_token))
                    {
                        settings.Set<string>(FACEBOOK_TOKEN_SETTING, tokenResponse.access_token);
                        settings.Set(FACEBOOK_TOKEN_EXPIRES_AT_SETTING, DateTime.UtcNow.AddSeconds((int)tokenResponse.expires).ToFileTimeUtc());
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
开发者ID:johanlindfors,项目名称:AssemblySplitting,代码行数:28,代码来源:FacebookService.cs

示例10: API

 public static void API(
     string endpoint,
     HttpMethod method,
     FacebookDelegate callback)
 {
     if (method != HttpMethod.GET) throw new NotImplementedException();
     Task.Run(async () =>
     {
         FacebookClient fb = new FacebookClient(_fbSessionClient.CurrentAccessTokenData.AccessToken);
         FBResult fbResult = null;
         try
         {
             var apiCall = await fb.GetTaskAsync(endpoint, null);
             if (apiCall != null)
             {
                 fbResult = new FBResult();
                 fbResult.Text = apiCall.ToString();
                 fbResult.Json = apiCall as JsonObject;
             }
         }
         catch (Exception ex)
         {
             fbResult = new FBResult();
             fbResult.Error = ex.Message;
         }
         if (callback != null)
         {
             Utils.RunOnUnityAppThread(() => { callback(fbResult); });
         }
     });
 }
开发者ID:JeffreyKimani,项目名称:unityplugins,代码行数:31,代码来源:FB.cs

示例11: Login

        public async Task<HttpResponseMessage> Login(string authToken)
        {
            var fb = new FacebookClient(authToken);
            fb.AppSecret = Environment.GetEnvironmentVariable("FacebookSecret");
            dynamic result = await fb.GetTaskAsync("me");
            var existingUser = (User)await _userService.GetUser(result.id);
            if (existingUser == null)
            {
                var newUser = await _userService.CreateUser(new User
                {
                    Id = Guid.NewGuid(),
                    FacebookId = result.id.ToString(),
                    FacebookToken = authToken,
                    Name = result.name.ToString(),
                    UpdatedAt = DateTime.Now
                });
                
                return Request.CreateResponse(HttpStatusCode.OK, newUser);
            }

            existingUser.Name = result.name.ToString();
            existingUser.FacebookToken = authToken;
            existingUser.UpdatedAt = DateTime.Now;

            var updatedUser = await _userService.UpdateUser(existingUser);

            return Request.CreateResponse(HttpStatusCode.OK, updatedUser);
        }
开发者ID:EolAncalimon,项目名称:Locality,代码行数:28,代码来源:UserController.cs

示例12: LoadUserInfo

        private void LoadUserInfo()
        {
            var fb = new FacebookClient(App.AccessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }

                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    var profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", App.FacebookId, "square", App.AccessToken);

                    this.MyImage.Source = new BitmapImage(new Uri(profilePictureUrl));
                    this.MyName.Text = String.Format("{0} {1}", (string)result["first_name"], (string)result["last_name"]);
                });
            };

            fb.GetTaskAsync("me");
        }
开发者ID:CrisL,项目名称:SunshineLab,代码行数:25,代码来源:LandingPage.xaml.cs

示例13: OnFacebookAuthenticationFinished

        private async void OnFacebookAuthenticationFinished(AccessTokenData session)
        {
            // here the authentication succeeded callback will be received.
            // put your login logic here
            try
            {
                FacebookClient client = new FacebookClient(session.AccessToken);

                //Graph request and result
                dynamic result = await client.GetTaskAsync("me");

                //Getting current user from graph request result
                var currentUser = new Facebook.Client.GraphUser(result);

                //Do something with current user data
                var fad = new FacebookAccountData()
                {
                    SocialNetworkId = currentUser.Id,
                    Name = currentUser.Name,
                    LastName = currentUser.LastName,
                    FirstName = currentUser.FirstName,
                    Email = "",
                    Link = currentUser.Link,
                    MiddleName = currentUser.MiddleName
                };
            }
            catch (Exception ex)
            {
                //Handle exception
            }
        }
开发者ID:CuljakIvan,项目名称:Xamarin,代码行数:31,代码来源:App.xaml.cs

示例14: RetriveUserInfo

        private async System.Threading.Tasks.Task RetriveUserInfo(AccessTokenData accessToken)
        {
            var client = new Facebook.FacebookClient(accessToken.AccessToken);

			dynamic result = null;
			bool failed = false;
			try
			{
				result = await client.GetTaskAsync("me?fields=id,birthday,first_name,last_name,middle_name,gender");
			}
			catch(Exception e)
			{
				failed = true;
			}
			if(failed)
			{
				MessageDialog dialog = new MessageDialog("Facebook is not responding to our authentication request. Sorry.");
				await dialog.ShowAsync();

				throw new Exception("Windows phone does not provide an exit function, so we have to crash the app.");
			}
            string fullName = string.Join(" ", new[] { result.first_name, result.middle_name, result.last_name });
            string preferredName = result.last_name;
            bool? gender = null;
            if (result.gender == "female")
            {
                gender = true;
            }
            else if (result.gender == "male")
            {
                gender = false;
            }
            DateTime birthdate = DateTime.UtcNow - TimeSpan.FromDays(365 * 30);
            if (result.birthday != null)
            {
                birthdate = DateTime.Parse(result.birthday);
            }

            var currentUser = new Facebook.Client.GraphUser(result);

            long facebookId = long.Parse(result.id);

            UserState.ActiveAccount = await Api.Do.AccountFacebook(facebookId);
            if (UserState.ActiveAccount == null)
            {
                Frame.Navigate(typeof(CreatePage), new CreatePage.AutofillInfo
                    {
                        SocialId = facebookId,
						Authenticator = Authenticator.Facebook,
                        Birthdate = birthdate,
                        FullName = fullName,
                        Gender = gender,
                        PreferredName = preferredName
                    });
            }
            else
            {
                Frame.Navigate(typeof(MainPage), UserState.CurrentId);
            }
        }
开发者ID:tblue1994,项目名称:SoftwareEngineeringProject2015,代码行数:60,代码来源:FacebookAuthentication.xaml.cs

示例15: graphCallButton_Click

        async private void graphCallButton_Click(object sender, RoutedEventArgs e)
        {
            FacebookClient fb = new FacebookClient(Session.ActiveSession.CurrentAccessTokenData.AccessToken);

            dynamic friendsTaskResult = await fb.GetTaskAsync("/me/friends");

            MessageBox.Show("Graph Request for /me/friends: " +
                friendsTaskResult.ToString());
        }
开发者ID:alykhaled,项目名称:facebook-winclient-sdk,代码行数:9,代码来源:MainPage.xaml.cs


注:本文中的Facebook.FacebookClient.GetTaskAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。