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

后端 未结 5 1001
花落未央
花落未央 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:38

    Here is an example of a custom button if you want to make one :)

    FbLoginButton() {
     LoginManager
      .logInWithReadPermissions(['public_profile'])
      .then(function (result) {
        if (result.isCancelled) {
          alert('Login cancelled');
        } else {
          AccessToken
            .getCurrentAccessToken()
            .then((data) => {
              let accessToken = data.accessToken
              alert(accessToken.toString())
    
              const responseInfoCallback = (error, result) => {
                if (error) {
                  console.log(error)
                  alert('Error fetching data: ' + error.toString());
                } else {
                  console.log(result)
                  alert('Success fetching data: ' + result.toString());
                }
              }
    
              const infoRequest = new GraphRequest('/me', {
                accessToken: accessToken,
                parameters: {
                  fields: {
                    string: 'email,name,first_name,middle_name,last_name'
                  }
                }
              }, responseInfoCallback);
    
              // Start the graph request.
              new GraphRequestManager()
                .addRequest(infoRequest)
                .start()
    
            })
        }
      }, function (error) {
        alert('Login fail with error: ' + error);
       });
      }
    

提交回复
热议问题