【问题标题】:FBSDKGraphRequest in React Native returning incomplete objectReact Native中的FBSDKGraphRequest返回不完整的对象
【发布时间】:2015-12-01 21:03:08
【问题描述】:

所以我已经实现了 react native FBSDKGraphRequest 和登录按钮。登录工作正常,但是当我尝试用户的图形请求时,我希望 /me 端点返回而不是完整的对象

{ "id": "162036280799349", "birthday": "08/08/1980", "email": "test_ppjeffg_eight\u0040tfbnw.net", "first_name": "Test", "gender": "male", "last_name": "Eight", "link": "https://www.facebook.com/app_scoped_user_id/162036280799349/", "locale": "en_US", "name": "Test Eight", "timezone": -8, "updated_time": "2015-07-28T18:22:16+0000", "verified": false }

我才明白

Object {name: "Test Eight", id: "162036280799349"}

尽管我已根据文档完成所有操作,但我很可能会错误地执行请求。以下是相关源代码:

class LoadingOverlay extends BaseComponent{
    constructor(props){
        super(props);
        this._bind(/*'_fetchFriendsRequestFunction'*/);
        this.state = {isVisible: true,
                  token: null,
                  profileInfo: null}


    }

  _fetchGraphRequestFunction(){
    console.log("start");
    var fetchProfileRequest = new FBSDKGraphRequest((error, result) => {
  if (error) {
    alert('Error making request.');
  } else {
    // Data from request is in result
    console.log(result);
  }
}, '/me');
// Start the graph request.
fetchProfileRequest.start();

  }

    render(){
        return(
            <Overlay isVisible={this.state.isVisible}>
            <BlurView style={styles.background} blurType="dark">
            <FBSDKLoginButton
                onLoginFinished={(error,result)=>{
                    if (error){
                        alert('Error Logging In.');
                    } else {
                        if (result.isCanceled){
                            alert('Login Cancelled.');
                        } else {
                            FBSDKAccessToken.getCurrentAccessToken((token)=>{
                                console.log(token.tokenString);
                this._fetchGraphRequestFunction();
                            })


                        }
                    }
                }}
                onLogoutFinished={()=>console.log('Logged Out.')}
                readPermissions={['public_profile', 'email', 'user_birthday', 'user_friends']}
                publishPermissions={['publish_actions']}/>
            </BlurView>

      </Overlay>
        );
    }
}`

【问题讨论】:

    标签: ios react-native fbsdk


    【解决方案1】:

    您可以向 Facebook 请求其他参数,方法是像这样将它们附加到 uri:

    /me?fields=id,name,email
    

    或通过调用 FBSDKGraphRequest 对象上的 addStringParameter 函数,如下所示:

    fetchProfileRequest.addStringParameter('picture,email,gender','fields');
    

    但是,你得到什么字段取决于你的应用的权限和用户的设置。

    另外,请注意 ios FB sdk 文档中的这个小技巧:https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginButton/

    注意,如果指定了读取权限,则不应指定发布权限。

    所以尝试发送一个空的 publishPermissions 参数,看看是否修复了它。

    更多信息在这里: Publish or manage permissions are not permited to to be requested with read permissions FACEBOOK SDK

    https://coderwall.com/p/gkeqcq/request-read-and-publish-permissions-simultaneously-using-ios-facebook-support

    如果有人有的话,我很想看到一个流程示例,以使这项工作在本机反应中工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      相关资源
      最近更新 更多