skip to Main Content

How do I get the user ID mail picture and so on? The picture is very important. I already tried different examples but they didn’t work. I want to show the picture on a second screen but that’s not so important at the moment.Sorry I am new to this and don’t really know what to do.

  import React from 'react';
  import {
    StyleSheet,
    Text,
    View,
    Button,
    Alert,
    TouchableOpacity,
    TextInput,
    Switch,
    Image
  } from 'react-native';
  import EStyleSheet from 'react-native-extended-stylesheet';
  import { LoginManager,LoginButton,AccessToken,GraphRequest,GraphRequestManager} from 'react-native-fbsdk';
  import { createStackNavigator } from 'react-navigation';
  import * as firebase from 'firebase';


  EStyleSheet.build({
      $textColor: 'white'
    });


  export default class HomeScreen extends React.Component {
      constructor(props){
          super(props);
          this.state = {userInfo: null,};
      }
      static navigationOptions = {
          title: "Socialmedia", 
      };
      renderImage(){

            console.log(this.state.userInfo);
            this.render(
              <View>
                <Image source={{url: this.state.userInfo.photoURL}} />
              </View>
            )
      }
      //Facebook login
      async loginWithFacebook() {
    try {
      const {
        type,
        token,
        expires,
        permissions,
        declinedPermissions,
      } = await Expo.Facebook.logInWithReadPermissionsAsync('262997934355158', {
        permissions: ['public_profile'],
      });
      if (type === 'success') {
        const credential = firebase.auth.FacebookAuthProvider.credential(token)
        //this.props.navigation.navigate('Second', {});
        firebase.auth().signInAndRetrieveDataWithCredential(credential).catch((error) => {
          console.log(error)
        })
        // Get the user's name using Facebook's Graph API
        const response = await fetch(`https://graph.facebook.com/me?access_token=${token}&fields=id,name,picture,type(large)`);
        const userInfo = await response.json();
        this.setState({userInfo});
        this.renderImage();
      } else {
        // type === 'cancel'
      }
    } catch ({ message }) {
      alert(`Facebook Login Error: ${message}`);
    }
  }
  //Google login
        async loginWithGoogle() {
          const { type, token } = await await Expo.Google.logInAsync({
              //androidClientId: YOUR_CLIENT_ID_HERE,
              iosClientId: '258088831368-h42kgsqarctlpuaugksgqeh6plkh0ese.apps.googleusercontent.com',
              scopes: ['profile', 'email'],
            });
          if (type == 'success') {
            const credential = firebase.auth.GoogleAuthProvider.credential(token)
            firebase.auth().signInAndRetrieveDataWithCredential(credential).catch((error) => {
              console.log(error)
            })
          }
        }
        //339771303079-3mse4b0pvur499bof3ri61heahjtsj9f.apps.googleusercontent.com
      render() {
          return(
          <View style={styles.container}>
              <View style={styles.container}><TouchableOpacity style={[styles.buttons, {backgroundColor: '#3b5998'}]} onPress={this.loginWithFacebook.bind(this)}>
              <Image style={styles.img} source={require("../assets/Facebook.png")}/><Text style={{left: 20, color: 'white'}}>Facebook</Text>
              </TouchableOpacity></View>
              <View style={styles.container}><TouchableOpacity style={styles.buttons} onPress={() => this.loginWithGoogle()}>
              <Image style={styles.img} source={require("../assets/Google.png")}/><Text style={{left: 20}}>Login with Google</Text>
              </TouchableOpacity></View>
              <View style={styles.container}><TouchableOpacity style={styles.buttons}>
              <Text>Github</Text>
              </TouchableOpacity></View>
              <View style={styles.container}><TouchableOpacity style={styles.buttons}>
              <Text>Play Spiele</Text>
              </TouchableOpacity></View>
              <View style={styles.container}><TouchableOpacity style={styles.buttons}>
              <Text>Twitter</Text>
              </TouchableOpacity></View>
          </View>
          );
      }
  }
  })

Thats the debug message:
{error: {…}}
error
:
{message: “Syntax error “Expected end of string instead of “(“.” at character 20: id,name,picture,type(large)”, type: “OAuthException”, code: 2500, fbtrace_id: “DXFuk9C8gdT”}
proto
:
Objec

2

Answers


  1. The syntax error tells you that there is something wrong with the API call:

    Wrong

    picture,type(large)
    

    Correct

    picture.type(large)
    

    Btw, you can (and should) always try API calls in the API Explorer first: https://developers.facebook.com/tools/explorer/

    Login or Signup to reply.
  2. you don’t need extra requests.

    Simply do this.

    firebase.auth().signInAndRetrieveDataWithCredential(credential)
    .then(data => {
      let {photoURL} = data.user
      // now you got the photoURL
      // to retrieve different sizes of photo url simply do
      let largerImage = photoURL+"?height=600"
    })
    

    a simple request.

    height=600 will adjust the photo size depends on the original photos’ width&height properties, and return appropriate size of image. It will return above the 600 but not below. Because of the image could be not in a square format.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search