首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本能的反应。检索所有屏幕上的facebook登录结果

本能的反应。检索所有屏幕上的facebook登录结果
EN

Stack Overflow用户
提问于 2017-05-10 07:31:22
回答 1查看 771关注 0票数 0

我正在制作一个带有facebook登录的本地ios应用程序,现在需要在所有其他屏幕上检索结果数据。

我有树幕:

  • Login.js
  • Profile.js
  • Main.js

登录包含工作的loginButton女巫,并返回控制台中的用户public_profile。

Main包含一个堆栈导航器并导入其他屏幕。

配置文件是我想打印的登录用户名,img等。

问题是,当onLoginFinished成功时,它会返回用户信息,但是如何在其他屏幕上获取它呢?

看上去这是我需要的GraphRequestManager和infoRequest,但却想不出怎么做。

Main.js

代码语言:javascript
复制
'use-strict';
var React = require('react');
window.React = React;
import {AppRegistry, Text} from 'react-native';
import { StackNavigator } from 'react-navigation';

//login screen
import Login from './Login'

//profile screen
var Profile = require('./Profile.js');

const skatebayApp = StackNavigator({
  Login: {screen: Login},
  Profile: {screen: Profile},
},{
  headerMode: 'screen',
});

AppRegistry.registerComponent('skatebayApp', () => skatebayApp);

Login.js

代码语言:javascript
复制
'use-strict';
import React, { Component } from 'react';
import {
  Text,
  View,
  TouchableHighlight,
  Image,
} from 'react-native';

const FBSDK = require('react-native-fbsdk');
const {
  LoginButton,
  AccessToken,
  GraphRequest,
  GraphRequestManager,
} = FBSDK;

export default class Login extends Component{

  render(){
    return(

    <LoginButton
      onLoginFinished={
        (error, result) => {
          if (error) {
            alert("login has error: " + result.error);
          } else if (result.isCancelled) {
            alert("login is cancelled.");
          } else {

            AccessToken.getCurrentAccessToken().then((data) => {
              let accessToken = data.accessToken

              const responseInfoCallback = (error, result) => {
                if (error) {
                  console.log(error)
                  alert('Error fetching data: ' + error.toString());
                } else {
                  console.log(result)
                }
              }
              const infoRequest = new GraphRequest(
                '/me',
                {
                  accessToken: accessToken,
                    parameters: {
                      fields: {
                      string: 'email,name,first_name,last_name,picture'
                      }
                    }
                },
                responseInfoCallback,
                console.log(result)
              );
              new GraphRequestManager().addRequest(infoRequest).start()
            })
          }
        }
      } onLogoutFinished={() => console.log('signed out')}/>
  );
 }
}

Profile.js -我想在这里获取用户信息并打印出来

代码语言:javascript
复制
'use-strict';
import React, { Component } from 'react';
import {
  AppRegistry,
  Text,
  View,
  Image,
} from 'react-native';
import { StackNavigator } from 'react-navigation';


class Profile extends React.Component {

   render() {
   return (
      <View>
        <Text>Username & other info here</Text>
      </View>
   );
  }
}
module.exports = Profile;

希望这有什么意义,我对本族语的反应很新鲜。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-10 10:21:42

将用户详细信息存储在异步存储中,然后可以从任何屏幕访问它。您可以在这里找到更多详细信息,https://facebook.github.io/react-native/docs/asyncstorage.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43886128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档