expoClientID应该放在哪里?

huangapple go评论46阅读模式
英文:

Where does the expoClientID go?

问题

我正在为我的Expo应用添加Facebook登录,文档中说要在某个地方输入我的expoClientId

问题是我不知道该放在哪里。是放在app.json吗?或者是package.json?是在Facebook开发者门户的某个地方吗?还是在Expo控制台的某个地方?

有人知道expoClientId应该放在哪吗? 文档没有说明放在哪里。

编辑:看起来我还需要放置iosClientIdandroidClientId

英文:

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 &#39;react&#39;;
import * as WebBrowser from &#39;expo-web-browser&#39;;
import * as Facebook from &#39;expo-auth-session/providers/facebook&#39;;
import { ResponseType } from &#39;expo-auth-session&#39;;
import { initializeApp } from &#39;firebase/app&#39;;
import { getAuth, FacebookAuthProvider, signInWithCredential } from &#39;firebase/auth&#39;;
import { Button } from &#39;react-native&#39;;

// Initialize Firebase
initializeApp({
   /* Config */
});

WebBrowser.maybeCompleteAuthSession();

export default function App() {
   const [request, response, promptAsync] = Facebook.useAuthRequest({
     responseType: ResponseType.Token,
     clientId: &lt;YOUR FBID&gt;,
     expoClientId: &lt;YOUR FBID&gt;, //this is where you add them
     iosClientId: &lt;YOUR FBID&gt;, 
     androidClientId: &lt;YOUR FBID&gt;,
   });

   React.useEffect(() =&gt; {
     if (response?.type === &#39;success&#39;) {
        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 (
      &lt;Button
        disabled={!request}
        title=&quot;Login&quot;
        onPress={() =&gt; {
          promptAsync();}}
      /&gt;
   );
}

huangapple
  • 本文由 发表于 2023年2月8日 23:46:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定