2017-04-03 64 views
0

我正在尝试使用react-native-fbsdk发布到facebook组。 我一遍又一遍地得到同样的错误,说“请求参数需要是带有'字符串'字段的对象。” 评论的代码给出了相同的错误。Post-image with react-native-fbsdk

这是我的代码:

const getToken = await AccessToken.getCurrentAccessToken(); 

    const postRequestParameters = { 
     fields: { 
      message: { 
       string: 'message' 
      } 
     } 
     //fields: { 
     // message: 'message' 
     //} 
    }; 

    const config = { 
     httpMethod: 'POST', 
     version: 'v2.8', 
     parameters: postRequestParameters, 
     accessToken: getToken.accessToken.toString() 
    }; 

    const infoRequest = new GraphRequest(
     '/1017038678426598/feed', 
     config, 
     this.postToFBCallback, 
    ); 

    new GraphRequestManager().addRequest(infoRequest).start(); 

error

任何想法,我做错了什么?我一直在Google上搜索几天,但没有运气。

回答

-1

我终于找到了适合我的问题的解决方案。

代码:

const xhr = new XMLHttpRequest(); 

    const photo = { 
     uri: this.props.imgUri, 
     type: 'image/jpeg', 
     name: 'photo.jpg', 
    }; 

    let body = new FormData(); 
    body.append('photo', photo); 

    xhr.onreadystatechange =() => { 
     if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { 
      this.setState({ 
       message: '', 
       loading: false 
      }); 
      Actions.pop(); 
      Alert.alert('', 'Ditt meddelande delades!'); 
    } 
}; 

xhr.ontimeout = (e) => { 
     Alert.alert('Error', e); 
}; 

    xhr.open('POST', `https://graph.facebook.com/v2.8/${feedID}/photos?caption=${message}&access_token=${access_token}`); 
    xhr.send(body);