英文:
Where does the expoClientID go?
问题
我正在为我的Expo应用添加Facebook登录,文档中说要在某个地方输入我的expoClientId。
问题是我不知道该放在哪里。是放在app.json吗?或者是package.json?是在Facebook开发者门户的某个地方吗?还是在Expo控制台的某个地方?
有人知道expoClientId应该放在哪吗? 文档没有说明放在哪里。
编辑:看起来我还需要放置iosClientId和androidClientId。
英文:
I am adding Facebook login to my expo app and it says in the documentation to enter my expoClientId somewhere.
The problem is I cant figure out where to put it. Do I put it in my app.json? Maybe my package.json? In the Facebook developer portal somewhere? Maybe I put it in my expo console somewhere?
Does anyone know where the expoClientId should live? The documentation doesn't say where to put it.
Edit: It looks like I also need to place an iosClientId and an androidClientId as well.
答案1
得分: 3
这似乎是FacebookAuthRequestConfig接口的一部分,它被用作useAuthRequest()的参数(Expo源代码)。
英文:
It seems it's a part of the FacebookAuthRequestConfig interface which is used as useAuthRequest() parameter (Expo src).
答案2
得分: 2
居然是在请求中这样传递它来授权 Facebook:
    import * as React from 'react';
    import * as WebBrowser from 'expo-web-browser';
    import * as Facebook from 'expo-auth-session/providers/facebook';
    import { ResponseType } from 'expo-auth-session';
    import { initializeApp } from 'firebase/app';
    import { getAuth, FacebookAuthProvider, signInWithCredential } from 'firebase/auth';
    import { Button } from 'react-native';
    // 初始化 Firebase
    initializeApp({
       /* 配置 */
    });
 
    WebBrowser.maybeCompleteAuthSession();
    export default function App() {
       const [request, response, promptAsync] = Facebook.useAuthRequest({
         responseType: ResponseType.Token,
         clientId: <YOUR FBID>,
         expoClientId: <YOUR FBID>, // 在这里添加
         iosClientId: <YOUR FBID>, 
         androidClientId: <YOUR FBID>,
       });
       React.useEffect(() => {
         if (response?.type === 'success') {
            const { access_token } = response.params;
            const auth = getAuth();
            const credential = FacebookAuthProvider.credential(access_token);
            // 使用来自 Facebook 用户的凭据登录。
            signInWithCredential(auth, credential);
          }
        }, [response]);
       return (
          <Button
            disabled={!request}
            title="Login"
            onPress={() => {
              promptAsync();}}
          />
       );
    }
英文:
Turns out you pass it in the request to authorize with facebook like this:
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
import * as Facebook from 'expo-auth-session/providers/facebook';
import { ResponseType } from 'expo-auth-session';
import { initializeApp } from 'firebase/app';
import { getAuth, FacebookAuthProvider, signInWithCredential } from 'firebase/auth';
import { Button } from 'react-native';
// Initialize Firebase
initializeApp({
   /* Config */
});
WebBrowser.maybeCompleteAuthSession();
export default function App() {
   const [request, response, promptAsync] = Facebook.useAuthRequest({
     responseType: ResponseType.Token,
     clientId: <YOUR FBID>,
     expoClientId: <YOUR FBID>, //this is where you add them
     iosClientId: <YOUR FBID>, 
     androidClientId: <YOUR FBID>,
   });
   React.useEffect(() => {
     if (response?.type === 'success') {
        const { access_token } = response.params;
        const auth = getAuth();
        const credential = FacebookAuthProvider.credential(access_token);
        // Sign in with the credential from the Facebook user.
        signInWithCredential(auth, credential);
      }
    }, [response]);
   return (
      <Button
        disabled={!request}
        title="Login"
        onPress={() => {
          promptAsync();}}
      />
   );
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论