githubとFacebook developers docsの両方の文書を読んだ。
サンプルだけあり、それ以上はありません。 APIドキュメントはありません。
react-native-fbsdkでグラフAPIを使用するには?
グラフ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をチェックしてください!それは(アラートを使用)し、正常表示:一部ユーザー情報(フルネーム例)を取得するために反応し、ネイティブfbsdk でをグラフAPIを使用する方法
?
GraphRequest()の各パラメータはですか?
のエラーオブジェクトとの結果はのオブジェクトはの_responseInfoCallbackの構造は何ですか? @Samuelの答えに
SOLUTION
おかげで、私は私のコード
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()については、以下を行う必要があり「Debug JS remote」を使用してChromeデベロッパーツールを開き、ログを表示します。
親愛なる@Samuel、ありがとうございました。私はどこでmeow_accesstokenを使うべきか疑問に思います。私が知っているように、これらのグラフAPIリクエストにはアクセストークンが必要ですが、私はあなたのコードでそれを見ていません。 –
申し訳ありませんが、私のコードにはいくつかのバグがありました。私はそれを更新してテストしましたが、今は正しく動作しています。私は、AccessTokenの約束の中でGraphブロックを移動し、GraphRequestにaccessToken paramを追加しました。 私がしたことをよりよく理解するために編集履歴を見てください:) –
投稿していただきありがとうございます。私はなぜパラメータオブジェクトがFacebook上で文書化されていないのかわかりません。 v0.3.0を使用して私のGraphRequestでAccessTokenが必要であることがわかりませんでした。 – AndrewHenderson