React native无法将读取权限(email)传递给发布授权请求

时间:2018-05-23 05:23:37

标签: javascript react-native

我正在反应原生app中实现fb sdk。我已完成link的所有更改,并在android设备中运行。应用程序在Facebook登录按钮单击时崩溃,这些是日志。

05-23 10:42:20.559 7063-7063/com.fbsample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.fbsample, PID: 7063
    Cannot pass a read permission (email) to a request for publish authorization
        at com.facebook.login.LoginManager.validatePublishPermissions(LoginManager.java:444)
        at com.facebook.login.LoginManager.logInWithPublishPermissions(LoginManager.java:416)
        at com.facebook.login.widget.LoginButton$LoginClickListener.performLogin(LoginButton.java:753)
        at com.facebook.login.widget.LoginButton$LoginClickListener.onClick(LoginButton.java:725)
        at com.facebook.FacebookButtonBase$1.onClick(FacebookButtonBase.java:384)
        at android.view.View.performClick(View.java:4785)
        at android.view.View$PerformClick.run(View.java:19884)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5343)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

我搜索了很多,但没有人帮助我摆脱这个问题。

至少错误应包含要做的建议。

我被困在几个小时:/

facebook doc没有什么新内容。

我有 FBLoginButton.js

    import React, { Component } from 'react';
    import { View } from 'react-native';
    import { LoginButton } from 'react-native-fbsdk';

    export default class FBLoginButton extends Component {
      render() {
        return (
          <View>
            <LoginButton
              publishPermissions={["email"]}
              onLoginFinished={
                (error, result) => {
                  if (error) {
                    alert("Login failed with error: " + error.message);
                  } else if (result.isCancelled) {
                    alert("Login was cancelled");
                  } else {
                    alert("Login was successful with permissions: " + result.grantedPermissions)
                  }
                }
              }
              onLogoutFinished={() => alert("User logged out")}/>
          </View>
        );
      }
    };

    module.exports = FBLoginButton;

App.js

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';
var FBLoginButton = require('./FBLoginButton');
const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.label}>Welcome to the Facebook SDK for React Native!</Text>
        <FBLoginButton />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

有人说出为什么这个问题仍然存在,我该怎么做才能解决它。

3 个答案:

答案 0 :(得分:4)

您必须将publishPermissions={["email"]}更改为readPermissions={["email"]}

答案 1 :(得分:1)

我将publishPermissions={["email"]}更改为publishPermissions={["publish_actions"]},一切正常。

答案 2 :(得分:0)

如果您想获取用户的电子邮件。您必须在readPermissions={['email']}的{​​{1}}上使用LoginButton。请注意,如果您已经使用react-native-fbsdk构建了React本机应用程序(如您的问题中所述),请删除该应用程序,然后重新构建。

此外,您只能使用publishPermissions={["email"]}readPermissions之一,不能同时使用两者。这是设计使然,如此处记录的:https://developers.facebook.com/docs/reference/android/current/class/LoginButton/#setReadPermissions

如果要在同一应用程序上使用publishPermissionsreadPermissions,则必须再次调用登录对话框。 publishPermissions为此提供react-native-fbsdk

  

LoginManager类用于请求会话的其他权限或使用自定义UI提供登录功能。与LoginButton一样,LoginManager类是从react-native-fbsdk模块加载的。下面的示例以最小的权限执行登录。   https://developers.facebook.com/docs/react-native/login