2015-08-14 11 views
6

Il risultato di onLoginFinished mi dice solo le autorizzazioni concesse. Da repo, non è chiaro come ottenere il profilo utente. Sembra che react-native-fbsdkcore debba avvolgere FBSDKProfile.h ma non vedere dove lo fa.react-native-fbsdk - come ottenere il profilo utente?

var FBSDKLogin = require('react-native-fbsdklogin'); 
    var { 
     FBSDKLoginButton, 
    } = FBSDKLogin; 

    var Login = React.createClass({ 
     render: function() { 
     return (
      <View> 
      <FBSDKLoginButton 
       onLoginFinished={(error, result) => { 
       if (error) { 
        alert('Error logging in.'); 
       } else { 
        if (result.isCanceled) { 
        alert('Login cancelled.'); 
        } else { 
        alert('Logged in.'); 
        } 
       } 
       }} 
       onLogoutFinished={() => alert('Logged out.')} 
       readPermissions={[]} 
       publishPermissions={['publish_actions']}/> 
      </View> 
     ); 
     } 
    }); 
+0

Ho trovato la soluzione per questo, Ecco la soluzione: const FBSDK = require ('react-native-fbsdk'); const { LoginButton, access token, GraphRequest, GraphRequestManager, } = FBSDK; http://stackoverflow.com/questions/37383888/how-to-use-graph-api-with-react-native-fbsdk –

risposta

3

Scoperto è possibile accedere al profilo utente con Graph API.

// Create a graph request asking for user's profile 
var fetchProfileRequest = new FBSDKGraphRequest((error, result) => { 
    if (error) { 
    alert('Error making request.'); 
    } else { 
    // Data from request is in result 
    } 
}, '/me'); 
// Start the graph request. 
fetchProfileRequest.start(); 
4

C'è un modo più semplice per farlo. Piuttosto che manualmente il grafico richiedere te, 'reagire-native-fbsdkcore' pacchetto per ottenere i dati associati con l'utente connesso (se esiste)

var

FBSDKCore = require('react-native-fbsdkcore'); 

var { 
    FBSDKAccessToken, 
} = FBSDKCore; 

FBSDKAccessToken.getCurrentAccessToken((token) => { 
    // token will be null if no user is logged in, 
    // or will contain the data associated with the logged in user 
}); 

indirizzo cphackm è che nel questo issue #2

+0

Come utilizzare la risposta per ottenere il nome, l'email, ecc. Degli utenti, grazie – alyn000r

+0

I non credere che FBSDK contenga tutte le informazioni dell'utente. È possibile utilizzare facilmente una richiesta di grafico per estrarre le informazioni necessarie, quindi archiviarle nell'archivio locale o in un altro stato. –

Problemi correlati