我閱讀了文檔,均在github和Facebook developers docs之間。
只有樣品,沒有更多。沒有API文檔。
如何使用圖形API與react-native-fbsdk?
做出圖形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());
}
}
,這裏是做一個圖形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,我現在在看什麼?
如何使用圖形API在反應,本機fbsdk檢索一些用戶信息(例如:全名)和成功顯示它(使用的警報)?
什麼參數GraphRequest()做什麼?
什麼是錯誤對象和結果在_responseInfoCallback對象的結構?
SOLUTION
感謝@Samuel答案,我已經更新了我的代碼
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開發者工具來查看日誌。
親愛的@Samuel,謝謝你的回覆。我想知道我應該在哪裏使用meow_accesstoken。據我所知,這些圖形API請求需要訪問令牌,但我沒有在代碼中看到它。 –
對不起,我的代碼有一些錯誤,我已經更新和測試它,現在它工作正常。我在AccessToken承諾中移動了Graph塊,並在GraphRequest上添加了accessToken參數。 請看看編輯歷史,以更好地瞭解我做了什麼:) –
感謝發佈。我不知道爲什麼參數對象沒有記錄在Facebook上。 我沒有發現我需要使用v0.3.0的GraphRequest上的AccessToken。 – AndrewHenderson