connected() { if (this.state.isConnected) return; // console.log("connected"); this.setState({ isConnected: true }); const that = this; window.FB.api("/me", (response) => { const message = `Welcome ${response.name}`; that.setState({ message }); that.getPages(); }); }
export function logOut() { return (dispatch: Dispatch<LoginActions>) => { window.FB.logout(() => { localStorage.removeItem('token'); // Dispatch the success action dispatch(logOutAction()); }); }; }
window.FB.api('/me', { locale: this.props.language, fields: this.props.fields }, (me) => { Object.assign(me, authResponse); this.props.callback(me); });
window.FB.login(response => { if (response.authResponse) { this.props.onLogin(null, response.authResponse); } else { this.props.onLogin(response); } }, { scope });
setFbAsyncInit() { const { appId, xfbml, cookie, version, autoLoad } = this.props; window.fbAsyncInit = () => { window.FB.init({ version: `v${version}`, appId, xfbml, cookie, }); this.setStateIfMounted({ isSdkLoaded: true }); if (autoLoad || window.location.search.includes('facebookdirect')) { window.FB.getLoginStatus(this.checkLoginAfterRefresh); } }; }
start() { if (this.state.isStarted) return; // console.log("started"); this.setState({ isStarted: true }); window.FB.getLoginStatus((response) => { // console.log("start=", response); if (response.status === "connected") { this.connected(); } }); }
getPages() { const that = this; // https://developers.facebook.com/docs/graph-api/reference/user/accounts/ window.FB.api("/me/accounts", (response) => { // console.log("getPages =", response); if (response && response.data) { that.setState({ pages: response.data }); } else { const message = "Error can't get pages "; that.setState({ message }); } }); }
componentDidMount() { window.fbAsyncInit = () => { window.FB.init({ appId: this.props.appId, cookie: true, version: "v2.8", }); window.FB.AppEvents.logPageView(); window.FB.Event.subscribe("auth.logout", this.onLogout.bind(this)); window.FB.Event.subscribe( "auth.statusChange", this.onStatusChange.bind(this),
window.FB.login(loginResponse => this.checkLoginState(loginResponse), true);
logout() { window.FB.logout(() => { // console.log("Logout"); this.setState({ isConnected: false }); }); }
login() { const that = this; window.FB.login( (response) => { if (response.authResponse) { // console.log("Welcome! Fetching your information.... "); that.connected(); } else { // console.log("User cancelled login or did not fully authorize."); } }, { scope: "public_profile,manage_pages" }, ); }