在我的反應本機應用程序,我通過Facebook處理用戶帳戶。我已成功將Facebook SDK連接到我的應用程序,並且我正在顯示「使用Facebook登錄」按鈕,當輕按時讓用戶使用Facebook登錄並將按鈕文本更改爲「註銷」。如果用戶點擊「註銷」,它會將其註銷並更改文本以進行登錄。基本上,我似乎具有登錄和註銷工作的基本功能。如何在反應本機和Facebook的sdk中管理用戶帳戶狀態?
我有幾個問題,雖然關於如何做任何超越此事關於用戶的狀態登錄到Facebook的方面。
其中之一,似乎用戶的登錄不會在應用程序的生命週期之間持續存在。如果我關閉了應用並重新打開它,它會提示我再次登錄,而不是記住我剛剛登錄並自動將我登錄到Facebook。有沒有辦法告訴它通過FacebookSDK輕鬆地緩存日誌?我想必須有,但Facebook的文檔似乎稀少。
此外,有沒有一種方法來檢查用戶的狀態,現在通過布爾屬性或只是說他們已登錄或不是。
下面是我目前的代碼,它成功地顯示了Facebook登錄和註銷按鈕以及處理登錄和註銷流程。
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
AccessToken,
GraphRequest,
GraphRequestManager,
} = FBSDK;
export default class FBReact extends Component {
render() {
return (
<View>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
alert(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}
onLogInFound={() => alert("log in found.")}/>
</View>
);
}
}
AppRegistry.registerComponent('FBReact',() => FBReact);
謝謝。我想知道是否有更好的方式來獲得Facebook登錄應用程序打開/關閉之間的持久性而不是使用AsyncStorage?看起來這種持久性將被嵌入到Facebook SDK中 –