React Native中的FBSDKGraphRequest返回不完整的对象

时间:2015-12-01 21:03:08

标签: ios react-native fbsdk

所以我已经实现了react本地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>
        );
    }
}`

1 个答案:

答案 0 :(得分:2)

您可以通过将这些参数附加到uri来请求Facebook中的其他参数:

/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

我很想看到一个流程的例子,如果有人拥有它,可以让这个工作以原生的方式工作。