How to use graph API with react-native-fbsdk?

后端 未结 5 999
花落未央
花落未央 2021-01-30 17:49

I read the document, both on github and Facebook developers docs.
There is only sample, nothing more. No API document.

The code to make a Graph API request is

5条回答
  •  时光说笑
    2021-01-30 18:24

    try this

    import { GraphRequest, GraphRequestManager } from 'react-native-fbsdk';
    
    export const GetInfoUSer = () => {
    
    return new Promise((resolve, reject) => {
    
        const infoRequest = new GraphRequest('/me', null, ((error, result) => {
            if (error) {
                reject(error)
            } else {
               resolve(result)
            }
        }))
    
        new GraphRequestManager().addRequest(infoRequest).start();
    
      })
    }
    

    and then

        onLoginConFacebook = () => {
    
        LoginManager.logInWithReadPermissions(['public_profile']).then(result => {
    
            if (result.isCancelled) {
                console.log(':(')
            } else {
    
                AccessToken.getCurrentAccessToken().then((data) => {
    
                    let myAccessToken = data.accessToken.toString();
    
                    GetInfoUSer().then(response => {
                        console.log(response)
                    }).catch(error => {
                        console.log(error)
                    })
                }
                ).catch(error => {
                    console.log(':(')
                })
            }
        })
    }
    

提交回复
热议问题