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


C# FacebookClient.TryParseOAuthCallbackUrl方法代码示例

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


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

示例1: FBLogin_Navigated

        private void FBLogin_Navigated(object sender, NavigationEventArgs e)
        {
            // whenever the browser navigates to a new url, try parsing the url.
            // the url may be the result of OAuth 2.0 authentication.

            var fb = new FacebookClient();
            FacebookOAuthResult oauthResult;
            if (fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication
                if (oauthResult.IsSuccess)
                {
                    var accesstoken = oauthResult.AccessToken;
                    FBLogin.IsEnabled = false;
                    accessToken = accesstoken;
                }
                else
                {
                    var errorDescription = oauthResult.ErrorDescription;
                    var errorReason = oauthResult.ErrorReason;
                }
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.

            }
        }
开发者ID:ysedletskaya,项目名称:LearningPart2,代码行数:28,代码来源:LoginDialog.xaml.cs

示例2: FaceBookLoginPageNavigated

        private async void FaceBookLoginPageNavigated(object sender, NavigationEventArgs e)
        {
            if (FaceBookLoginPage.Visibility == Visibility.Collapsed)
                return;
            FacebookOAuthResult oauthResult;
            var fb = new FacebookClient();

            if (!fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
            {
                return;
            }

            if (oauthResult.IsSuccess)
            {
                await ProcessFbOathResult(oauthResult);
                gridFBLoggedIn.Visibility = Visibility.Visible;
                FaceBookLoginPage.Visibility = Visibility.Collapsed;
                Dispatcher.BeginInvoke(() => DataContext = App.ViewModel.UserPreference);
                FaceBookLoginPage.Visibility = Visibility.Collapsed;
                gridFBLoggedIn.Visibility = Visibility.Visible;
                LinkButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                
                FaceBookLoginPage.Visibility=Visibility.Collapsed;
                gridFBLoggedIn.Visibility=Visibility.Collapsed;
                LinkButton.Visibility=Visibility.Visible;

            }
        }
开发者ID:peterdocter,项目名称:hydra,代码行数:31,代码来源:Settings.xaml.cs

示例3: webBrowser1_Navigated

        private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            // whenever the browser navigates to a new url, try parsing the url
            // the url may be the result of OAuth 2.0 authentication.
            FacebookOAuthResult oauthResult;

            var fb = new FacebookClient();
            if (fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication.
                if (oauthResult.IsSuccess)
                {

                    // we got the code here

                    fb.PostCompleted+=
                        (o, args) =>
                        {
                            // make sure to check that no error has occurred.
                            if (args.Error != null)
                            {
                                // make sure to access ui stuffs on the correct thread.
                                Dispatcher.BeginInvoke(
                                    () =>
                                    {
                                        MessageBox.Show(args.Error.Message);
                                        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                                    });
                            }
                            else
                            {
                                var result = (IDictionary<string, object>)args.GetResultData();
                                var accessToken = (string)result["access_token"];

                                // make sure to access ui stuffs on the correct thread.
                                Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/FacebookInfoPage.xaml?access_token=" + accessToken, UriKind.Relative)));
                            }
                        };

                    fb.PostAsync("oauth/access_token",new
                                                          {
                                                              client_id = AppId,
                                                              client_secret = AppSecret,
                                                              redirect_uri = RedirectUri,
                                                              code = oauthResult.Code
                                                          });
                }
                else
                {
                    // the user clicked don't allow or some other error occurred.
                    MessageBox.Show(oauthResult.ErrorDescription);
                }
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.
            }
        }
开发者ID:bertvan,项目名称:facebook-csharp-sdk,代码行数:58,代码来源:FacebookLoginPage.xaml.cs

示例4: wb_Navigated

 private void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     var fb=new FacebookClient();
     if (fb.TryParseOAuthCallbackUrl(e.Url, out result)) {
         if (result.IsSuccess) {
             this.Hide();
         } else {
             var errorDescription = result.ErrorDescription; var errorReason = result.ErrorReason;
         }
     }
 }
开发者ID:admirhodzic,项目名称:ClickShare,代码行数:11,代码来源:browser.cs

示例5: ParseResponse

		public FacebookOAuthResponse ParseResponse(HttpContext context)
		{
			var stateCookie = context.Request.Cookies[StateCookieName];
			context.Response.Cookies[FacebookAuthenticationProvider.StateCookieName].Expires = DateTime.Now.AddSeconds(-60);

			Guid cookieStateValue;
			Guid querystringStateValue;
			FacebookOAuthResult facebookResult;			

			var client = new FacebookClient();			

			if (stateCookie == null || !Guid.TryParse(stateCookie.Value, out cookieStateValue))
			{
				throw new AuthenticationException("State cookie not set");
			}

			if (!client.TryParseOAuthCallbackUrl(context.Request.Url, out facebookResult))
			{
				throw new AuthenticationException(string.Format("Request is not a valid Facebook OAuthCallbackUrl {0}", context.Request.Url));
			}

			if (!Guid.TryParse(facebookResult.State, out querystringStateValue) || cookieStateValue != querystringStateValue)
			{
				throw new AuthenticationException(string.Format("Response state value {0} does not equal state cookie {1}", querystringStateValue, cookieStateValue));
			}

			var url = string.Format(TokenUrl,
				FacebookConfig.FacebookAppId, context.Request.Url.GetLeftPart(UriPartial.Authority), FacebookConfig.FacebookAppSecret, facebookResult.Code);

			var response = new WebClient().DownloadString(new Uri(url));
			var p = HttpUtility.ParseQueryString(response);

			var token = p["access_token"];
			var expires = int.Parse(p["expires"]);

			client.AccessToken = token;
			dynamic me = client.Get("me");

			return new FacebookOAuthResponse
			{
				Token = token,
				ExpirySeconds = expires,
				User = me
			};
		}
开发者ID:VineMedia,项目名称:VineMedia.Facebook,代码行数:45,代码来源:FacebookAuthenticationProvider.cs

示例6: webBrowser_Navigated

        private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {

            try
            {
                // whenever the browser navigates to a new url, try parsing the url.
                // the url may be the result of OAuth 2.0 authentication.

                var fb = new FacebookClient();
                FacebookOAuthResult oauthResult;
                if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
                {
                    // The url is the result of OAuth 2.0 authentication
                    if (oauthResult.IsSuccess)
                    {
                        var accesstoken = oauthResult.AccessToken;
                        //webBrowser.Hide();
                        Wall wall = new Wall(accesstoken.ToString());
                        wall.Show();
                        this.Hide();                        
                    }
                    else
                    {
                        var errorDescription = oauthResult.ErrorDescription;
                        var errorReason = oauthResult.ErrorReason;
                    }
                }
                else
                {
                    // The url is NOT the result of OAuth 2.0 authentication.
                }
            }
            catch (Exception ex)
            {

                throw;
            }
            finally
            {

            }


        }
开发者ID:KasunKoswattha,项目名称:Facebook,代码行数:44,代码来源:Form1.cs

示例7: webBrowser1_Navigated

        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            // whenever the browser navigates to a new url, try parsing the url
            // the url may be the result of OAuth 2.0 authentication.

            var fb = new FacebookClient();
            FacebookOAuthResult oauthResult;
            if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication.
                this.FacebookOAuthResult = oauthResult;
                this.DialogResult = FacebookOAuthResult.IsSuccess ? DialogResult.OK : DialogResult.No;
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.
                this.FacebookOAuthResult = null;
            }
        }
开发者ID:bertvan,项目名称:facebook-csharp-sdk,代码行数:19,代码来源:FacebookLoginDialog.cs

示例8: CheckLogin

 //hämtar accesstoken efter login
 private void CheckLogin(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     var fb = new FacebookClient();
     FacebookOAuthResult oauthResult;
     if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
     {
         if (oauthResult.IsSuccess)
         {
             var accesstoken = oauthResult.AccessToken;
             fbEvents.Token = accesstoken;
             fbEvents.UserName(accesstoken);
             this.Visible = false;
         }
         else
         {
             var errorDescription = oauthResult.ErrorDescription;
             var errorReason = oauthResult.ErrorReason;
         }
     }
 }
开发者ID:submarines-and,项目名称:TacoHacker999,代码行数:21,代码来源:LoginFrame.cs

示例9: LoginRetorno

        public ActionResult LoginRetorno()
        {
            var _fb = new FacebookClient();
            FacebookOAuthResult oauthResult;
            //Pega o Code
            if (!_fb.TryParseOAuthCallbackUrl(Request.Url, out oauthResult))
            {
                //erro
            }

            if (oauthResult.IsSuccess)
            {
                //Pega o Access Token "permanente"

                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("client_id", ConfigurationManager.AppSettings["FacebookAppId"]);
                parameters.Add("redirect_uri", "http://localhost:2780/home/LoginRetorno");
                parameters.Add("client_secret", ConfigurationManager.AppSettings["FacebookAppSecret"]);
                parameters.Add("code", oauthResult.Code);

                dynamic result = _fb.Get("/oauth/access_token", parameters);

                var accessToken = result.access_token;
                //TODO:Guardar no banco
                Session["accessToken"] = accessToken;

                //Exemplo de uso
                var client = new FacebookClient(accessToken);
                dynamic me = client.Get("me");

                ViewBag.Usuario = me.ToString();
                ViewBag.MostraForm = true;
            }
            else
            {
                // user cancelled
            }
            return View("Index");
        }
开发者ID:rodolfofadino,项目名称:MvTechDay-Facebook,代码行数:39,代码来源:HomeController.cs

示例10: HasFacebookResponse

 public bool HasFacebookResponse( string response, FacebookClient session )
 {
     // if true is returned, there IS a response, so the caller can call the below FacebookCredentialResult
     FacebookOAuthResult oauthResult;
     return session.TryParseOAuthCallbackUrl( new Uri( response ), out oauthResult );
 }
开发者ID:Higherbound,项目名称:HBMobileApp,代码行数:6,代码来源:RockMobileUser.cs

示例11: webBrowser1_Navigated

 private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     var fb = new FacebookClient();
     FacebookOAuthResult oauthResult;
     if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
     {
         // The url is the result of OAuth 2.0 authentication
         if (oauthResult.IsSuccess)
         {
             var accesstoken = oauthResult.AccessToken;
             Data.Set("token", FB.ExtendToken(accesstoken));
             next.Show();
             this.Close();
         }
         else
         {
             var errorDescription = oauthResult.ErrorDescription;
             var errorReason = oauthResult.ErrorReason;
         }
     }
 }
开发者ID:hanyessam,项目名称:fb_group_archiver,代码行数:21,代码来源:Browser.cs

示例12: Authenticate

        /// <summary>
        /// Authenticates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="username">The username.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <returns></returns>
        public override Boolean Authenticate( HttpRequest request, out string username, out string returnUrl )
        {
            var fbClient = new FacebookClient();
            FacebookOAuthResult oAuthResult;

            if ( fbClient.TryParseOAuthCallbackUrl( request.Url, out oAuthResult ) && oAuthResult.IsSuccess )
            {
                try
                {
                    var redirectUri = new Uri( GetRedirectUrl( request ) );

                    dynamic parameters = new ExpandoObject();
                    parameters.client_id = GetAttributeValue( "AppID" );
                    parameters.client_secret = GetAttributeValue( "AppSecret" );
                    parameters.redirect_uri = redirectUri.AbsoluteUri;
                    parameters.code = oAuthResult.Code;

                    dynamic result = fbClient.Post( "oauth/access_token", parameters );

                    string accessToken = result.access_token;

                    fbClient = new FacebookClient( accessToken );
                    dynamic me = fbClient.Get( "me" );
                    string facebookId = "FACEBOOK_" + me.id.ToString();

                    UserLogin user = null;

                    var rockContext = new RockContext();
                    rockContext.WrapTransaction( () =>
                    {
                        // query for matching id in the user table
                        var userLoginService = new UserLoginService( rockContext );
                        user = userLoginService.GetByUserName( facebookId );

                        // if no user was found see if we can find a match in the person table
                        if ( user == null )
                        {
                            try
                            {

                                var familyChanges = new List<string>();
                                var familyMemberChanges = new List<string>();
                                var PersonChanges = new List<string>();

                                // determine if we can find a match and if so add an user login record

                                // get properties from Facebook dynamic object
                                string lastName = me.last_name.ToString();
                                string firstName = me.first_name.ToString();
                                string email = me.email.ToString();

                                var personService = new PersonService( rockContext );
                                var person = personService.Queryable( "Aliases" ).FirstOrDefault( u => u.LastName == lastName && u.FirstName == firstName && u.Email == email );

                                if ( person != null )
                                {
                                    // since we have the data enter the birthday from Facebook to the db if we don't have it yet
                                    DateTime birthdate = Convert.ToDateTime( me.birthday.ToString() );

                                    if ( person.BirthDay == null )
                                    {
                                        History.EvaluateChange( PersonChanges, "Birth Date", person.BirthDate, person.BirthDate );
                                        person.BirthDate = birthdate;

                                        rockContext.SaveChanges();
                                        HistoryService.SaveChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
                                            person.Id, PersonChanges );
                                    }
                                }
                                else
                                {
                                    person = new Person();
                                    person.IsSystem = false;
                                    person.RecordTypeValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
                                    person.RecordStatusValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING.AsGuid() ).Id;
                                    person.FirstName = me.first_name.ToString();
                                    person.LastName = me.last_name.ToString();
                                    person.Email = me.email.ToString();
                                    if ( me.gender.ToString() == "male" )
                                        person.Gender = Gender.Male;
                                    else if ( me.gender.ToString() == "female" )
                                        person.Gender = Gender.Female;
                                    else
                                        person.Gender = Gender.Unknown;
                                    person.BirthDate = Convert.ToDateTime( me.birthday.ToString() );
                                    person.EmailPreference = EmailPreference.EmailAllowed;

                                    GroupService.SaveNewFamily( rockContext, person, null, false );
                                }

                                user = UserLoginService.Create( rockContext, person, AuthenticationServiceType.External, this.TypeId, facebookId, "fb", true );

                            }
//.........这里部分代码省略.........
开发者ID:Ganon11,项目名称:Rock,代码行数:101,代码来源:Facebook.cs

示例13: OnPageFinished

            public override void OnPageFinished(WebView view, string url)
            {
                base.OnPageFinished (view, url);

                var fb = new FacebookClient ();
                FacebookOAuthResult oauthResult;
                if (!fb.TryParseOAuthCallbackUrl (new Uri (url), out oauthResult))
                {
                    return;
                }

                if (oauthResult.IsSuccess)
                {
                    // Facebook Granted Token
                    var accessToken = oauthResult.AccessToken;
                    LoginSucceded (accessToken);
                }
                else
                {
                    // user cancelled login
                    LoginSucceded (string.Empty);
                }
            }
开发者ID:dmerrill6,项目名称:MidgardMessenger,代码行数:23,代码来源:FBWebAuthActivity.cs

示例14: PopulateAccessToken

        public void PopulateAccessToken(string code)
        {
            if (!TokenExists())
            {
                string accessToken = null;

                var fb = new FacebookClient();
                FacebookOAuthResult oauthResult;
                if (fb.TryParseOAuthCallbackUrl(HttpContext.Current.Request.Url, out oauthResult))
                {
                    // The url is the result of OAuth 2.0 authentication
                    if (oauthResult.IsSuccess)
                    {
                        accessToken = oauthResult.AccessToken;
                    }
                    else
                    {
                        var errorDescription = oauthResult.ErrorDescription;
                        var errorReason = oauthResult.ErrorReason;
                    }
                }
                else
                {
                    // The url is NOT the result of OAuth 2.0 authentication.
                }
                if (string.IsNullOrWhiteSpace(accessToken))
                    accessToken = GetAccessToken(code);

                _storage.Store(StoreKey, accessToken);
            }
        }
开发者ID:payman81,项目名称:Ran-Nan-Doh-1,代码行数:31,代码来源:FacebookClientProvider.cs

示例15: Authenticate

        /// <summary>
        /// Authenticates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="username">The username.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <returns></returns>
        public override Boolean Authenticate( HttpRequest request, out string username, out string returnUrl )
        {
            var fbClient = new FacebookClient();
            FacebookOAuthResult oAuthResult;

            if ( fbClient.TryParseOAuthCallbackUrl( request.Url, out oAuthResult ) && oAuthResult.IsSuccess )
            {
                try
                {
                    var redirectUri = new Uri( GetRedirectUrl( request ) );

                    dynamic parameters = new ExpandoObject();
                    parameters.client_id = GetAttributeValue( "AppID" );
                    parameters.client_secret = GetAttributeValue( "AppSecret" );
                    parameters.redirect_uri = redirectUri.AbsoluteUri; 
                    parameters.code = oAuthResult.Code;

                    dynamic result = fbClient.Post( "oauth/access_token", parameters );

                    string accessToken = result.access_token;

                    fbClient = new FacebookClient( accessToken );
                    dynamic me = fbClient.Get( "me" );
                    string facebookId = "FACEBOOK_" + me.id.ToString();

                    // query for matching id in the user table 
                    var userLoginService = new UserLoginService();
                    var user = userLoginService.GetByUserName( facebookId );

                    // if not user was found see if we can find a match in the person table
                    if ( user == null )
                    {
                        try
                        {
                            // determine if we can find a match and if so add an user login record

                            // get properties from Facebook dynamic object
                            string lastName = me.last_name.ToString();
                            string firstName = me.first_name.ToString();
                            string email = me.email.ToString();

                            var personService = new PersonService();
                            var person = personService.Queryable().FirstOrDefault( u => u.LastName == lastName && u.FirstName == firstName && u.Email == email );

                            if ( person != null )
                            {
                                // since we have the data enter the birthday from Facebook to the db if we don't have it yet
                                DateTime birthdate = Convert.ToDateTime( me.birthday.ToString() );

                                if ( person.BirthDay == null )
                                {
                                    person.BirthDate = birthdate;
                                    personService.Save( person, person.Id );
                                }

                            }
                            else
                            {

                                var dvService = new DefinedValueService();

                                person = new Person();
                                person.IsSystem = false;
                                person.RecordTypeValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ) );
                                person.RecordStatusValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) );

                                person.FirstName = me.first_name.ToString();
                                person.LastName = me.last_name.ToString();
                                person.Email = me.email.ToString();

                                if ( me.gender.ToString() == "male" )
                                    person.Gender = Gender.Male;
                                else if ( me.gender.ToString() == "female" )
                                    person.Gender = Gender.Female;
                                else
                                    person.Gender = Gender.Unknown;

                                person.BirthDate = Convert.ToDateTime( me.birthday.ToString() );
                                person.DoNotEmail = false;

                                personService.Add( person, null );
                                personService.Save( person, null );
                            }

                            user = userLoginService.Create( person, AuthenticationServiceType.External, this.TypeId, facebookId, "fb", true, person.Id );
                        }
                        catch ( Exception ex )
                        {
                            string msg = ex.Message;
                            // TODO: probably should report something...
                        }

                        // TODO: Show label indicating inability to find user corresponding to facebook id
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:Rock,代码行数:101,代码来源:Facebook.cs


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