我在github和Facebook developers docs上阅读了文档。
只有样本,没有更多。无API文档。
发出Graph API请求的代码是
const infoRequest = new GraphRequest(
'/me',
null,
this._responseInfoCallback,
);
和回调
_responseInfoCallback(error: ?Object, result: ?Object) {
if (error) {
alert('Error fetching data: ' + error.toString());
} else {
alert('Success fetching data: ' + result.toString());
}
}
下面是发出Graph API请求的函数
testRequestGraphAPI(){
const infoRequest = new GraphRequest(
'/me',
null,
this._responseInfoCallback,
);
new GraphRequestManager().addRequest(infoRequest).start();
}
但是,我找不到任何进一步的文档。我不知道每个参数是做什么的。
上述代码的结果如下所示。
我也不知道如何得到结果。
但是,当我尝试将'\me‘修改为'me?fields=id,name’时,它失败了。尽管我已经请求允许
<LoginButton
publishPermissions={["publish_actions,user_birthday, user_religion_politics, user_relationships, user_relationship_details, user_hometown, user_location, user_likes, user_education_history, user_work_history, user_website, user_managed_groups, user_events, user_photos, user_videos, user_friends, user_about_me, user_status, user_games_activity, user_tagged_places, user_posts, user_actions.video, user_actions.news, user_actions.books, user_actions.music, user_actions.fitness, public_profile, basic_info"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
meow_accesstoken = data.accessToken
alert(meow_accesstoken.toString())
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
但它并没有打印出什么错误,只是对象对象。
所以,问题是我不理解Facebook提供的没有解释的示例代码。
这是我的问题,我真的需要你的帮助:
首先,请检查一下我当前正在查看的javascript code?
如何在react-native-fbsdk中使用图形接口来检索一些用户信息警报(示例:)并成功显示 it (使用警报)?
GraphRequest()中的每个参数都有什么作用?
_responseInfoCallback中的error对象和result对象的结构是什么?
解决方案
感谢@Samuel answer,我已经更新了我的代码
testRequestGraphAPI: function(){
const infoRequest = new GraphRequest(
'/me',
{
parameters: {
fields: {
string: 'email,name,first_name,middle_name,last_name' // what you want to get
},
access_token: {
string: meow_accesstoken.toString() // put your accessToken here
}
}
},
this._responseInfoCallback // make sure you define _responseInfoCallback in same class
);
new GraphRequestManager().addRequest(infoRequest).start();
}
和回调
_responseInfoCallback: function(error: ?Object, result: ?Object) {
alert("meow response");
if (error) {
alert('Error fetching data: ' + error.toString());
console.log(Object.keys(error));// print all enumerable
console.log(error.errorMessage); // print error message
// error.toString() will not work correctly in this case
// so let use JSON.stringify()
meow_json = JSON.stringify(error); // error object => json
console.log(meow_json); // print JSON
} else {
alert('Success fetching data: ' + result.toString());
console.log(Object.keys(result));
meow_json = JSON.stringify(result); // result => JSON
console.log(meow_json); // print JSON
}
}
*注意:对于console.log(),您需要使用[远程调试JS ],然后打开Chrome开发者工具查看日志。
https://stackoverflow.com/questions/37383888
复制相似问题