2017-09-05 59 views
0

我正在獲取登錄成功和accessToken。我做了沒有從fbsdk獲得電子郵件ID,原因是反應

我試圖

LoginManager.logInWithReadPermissions([ 
     'email', 
     'public_profile', 
     'user_likes', 
    ]) 

那麼這

LoginManager.logInWithPublishPermissions([ 
    'publish_actions', 
]).then((result) => { 
    if (result.isCancelled) { 
    console.log('Login cancelled'); 
    } else { 
    AccessToken.getCurrentAccessToken().then((data) => { 
     const accessToken = data.accessToken; 
     const responseInfoCallback = (error, result) => { 
     if (error) { 
      console.log(error); 
      console.log('Error fetching data=', error.toString()); 
     } else { 
      console.log('Success fetching data=', result.toString()); 
     } 
     }; 
     const infoRequest = new GraphRequest(
     '/me', 
     { 
      accessToken, 
      parameters: { 
      fields: { 
       string: 'email,name,first_name,middle_name,last_name', 
      }, 
      }, 
     }, 
     responseInfoCallback, 
    ); 
     new GraphRequestManager().addRequest(infoRequest).start(); 
    }); 
    } 
}); 

'登錄的權限成功', '電子郵件,public_profile' 和用戶配置文件數據是

{ first_name: 'XXXXXX', 
    name: 'XXXXXX YYYYY', 
    last_name: 'YYYYYY', 
    id: '1319989423636921696328130092' } 

但沒有得到用戶的電子郵件ID,這裏有什麼問題。 如何在應用程序中登錄Facebook後獲取電子郵件ID。

+0

而正是你要求訪問他們的電子郵件所必需的權限的用戶? – CBroe

+0

你能夠獲得名稱和其他細節? –

回答

1

這是我正在做它在我的項目中,併成功檢索電子郵件

LoginManager.logInWithReadPermissions(['public_profile', 'email', 'user_friends']).then(
      (result) => { 
       if (result.isCancelled) { 
        console.log('Login cancelled') 
       } else { 
        AccessToken.getCurrentAccessToken().then(
         (data) => { 
          this._fbHome();// Navigatin to next screen 
         } 
        ) 
       } 
      }, 
      (error) => { 
       console.log('Login fail with error: ' + error) 
      } 
     ) 

然後導航到下一個屏幕後,我提取用戶數據

const infoRequest = new GraphRequest(
     '/me?fields=name,email,picture.type(large)', 
     null, 
     this._responseInfoCallback 
    ); 
     new GraphRequestManager().addRequest(infoRequest).start(); 


_responseInfoCallback = (error, result) => { 
    if (error) { 
     alert('Error fetching data: ' + error.toString()); 
    } else { 
     this.setState({ userName: result.name, userEmail: result.email ,userPic:result.picture.data.url}); 
       AsyncStorage.setItem("UserName",this.state.userName); 
        AsyncStorage.setItem("Email", this.state.userEmail); 
        AsyncStorage.setItem("UserPic", this.state.userPic); 

     // SharedPreferences.setItem("UserName", this.state.userName); 
     //  SharedPreferences.setItem("Email", this.state.userEmail); 
     //  SharedPreferences.setItem("UserPic", this.state.userPic); 
     console.log("Picture"+ this.state.userPic + "Name" + this.state.userName + "Email" + this.state.userEmail); 
    } 
    } 
+0

{ID: 「1319989428136686664730092」,圖片:對象,名稱: 「DDDDDDDD」} ID : 「1319989428136686664730092 「 名稱:」 DDDDDDD 「 圖片:對象 數據:對象 is_silhouette :falseurl : 」?https://scontent.xx.fbcdn.ne – Sport

+0

你試試我的方法 –

+0

是你的方法只有 – Sport

1

修訂 你設置權限時,用戶在您的權限驗證,例如驗證碼

LoginManager.logInWithReadPermissions(['public_profile', 'email']) 
     .then(function (result) { 
      if (!result.isCancelled) { 
       return AccessToken.getCurrentAccessToken().then((data) => { 
        return initUser(data).then((user) => { 
         return { 
          name: user.name, 
          email: user.email, 
          photo: 'https://graph.facebook.com/' + user.id + '/picture?type=normal' 
         } 
        }) 
       }) 
      } 
     }).then((data) => { 
      this._navigateTo(this.props, data, 'Home') 
     }) 

集電子郵件代碼可以看到這樣

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

不是我已經試過 – Sport

+0

看到更新,它可以工作 –

+0

什麼是initUser這裏是什麼 – Sport

相關問題