我使用Facebook Graph API使用javascript fetch
方法请求一些用户数据。我在尝试使用Graph API Explorer https://developers.facebook.com/tools/explorer时返回的响应与返回到fetch方法的响应不同的问题。
在资源管理器中,响应返回了所有请求的数据,而在获取方法中,生日,位置和家乡缺失。那么这些反应差异背后的原因是什么?
以下是图谱API响应:
{
"id": "10152311252041311",
"birthday": "12/11/1992",
"age_range": {
"min": 21
},
"gender": "male",
"first_name": "Karim",
"last_name": "Elbawab",
"location": {
"location": {
"city": "Cairo",
"country": "Egypt",
"latitude": 30.0581,
"longitude": 31.2289
},
"id": "115351105145884"
},
"cover": {
"id": "10153054290206311",
"offset_y": 36,
"source": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/11080657_10153054290206311_8236239774331416126_o.jpg?oh=7a5e55ce637ddbcbdacb485c5830bbaf&oe=5998BAC0"
},
"picture": {
"data": {
"height": 958,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/c1.0.958.958/14492344_10154345907211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899",
"width": 958
}
},
"hometown": {
"location": {
"city": "Port Said",
"country": "Egypt",
"latitude": 31.2667,
"longitude": 32.3
},
"id": "106225446079687"
}
}
以下是我如何处理获取请求:
var url = "https://graph.facebook.com/v2.8/me?fields=birthday%2Cemail%2Cage_range%2Cabout%2Cgender%2Cfirst_name%2Clast_name%2Clocation%7Blocation%7D%2Ccover%2Cpicture.height(800).width(800)%2Chometown%7Blocation%7D&";
url += "access_token=" + accessToken.value;
fetch(url,{
method:"GET"
}).then(function(result){
var user_info = JSON.parse(result._bodyInit);
authentication_api.loginWithFacebook(user_info).then(function(res) {
callback(res);
});
}).catch(function(error){
console.log("Error: " + error);
callback(error);
});
}
获取响应:
{"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"cache-control":["private, no-cache, no-store, must-revalidate"],"x-fb-deb:["kHzlkaPnR7TExQXruPW/ibxz09g8LxiGsofdsFZVCUE4/ij1sebOSAcyn16osY3Q+4czC8MUT1Er5vrr3mueHg=="],"pragma":["no-cache"],"expires":["Sat, 01 Jan 2000 00:00:00 GMT"],"vary":["Accept-Encoding"],"x-fb-tracd":["G9ozccWmdM/"],"x-fb-rev":["2950242"],"x-android-selected-protocol":["http/1.1"],"x-android-response-source":["NETWORK 200"],"connection":["keep-alive"],"x-android-sent-millis":["1491911956237" content-type":["text/javascript; charset=UTF-8"],"date":["Tue, 11 Apr 2017 11:59:17 GMT"],"facebook-api-version":["v2.8"],"etag":["\"515d42cd12052847a3f24b113f810035508e12be\""],"null":["HTTP/1.1 2 OK"],"x-android-received-millis":["1491911956438"],"access-control-allow-origin":["*"]}},"url":"","_bodyInit":"{\"age_range\":{\"min\":21},\"gender\":\"male\",\"first_name\":\"Karim\",\"last_name\" Elbawab\",\"cover\":{\"id\":\"10153054290206311\",\"offset_y\":36,\"source\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t31.0-8\\/s720x720\\/11080657_10153054290206311_8236239774331416126_o.jpg?oh=755ce637ddbcbdacb485c5830bbaf&oe=5998BAC0\"},\"picture\":{\"data\":{\"height\":958,\"is_silhouette\":false,\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t1.0-1\\/c1.0.958.958\\/14492344_10154345211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899\",\"width\":958}},\"id\":\"10154881281451311\"}","_bodyText":"{\"age_range\":{\"min\":21},\"gender\":\"male\",\"first_ame\":\"Karim\",\"last_name\":\"Elbawab\",\"cover\":{\"id\":\"10153054290206311\",\"offset_y\":36,\"source\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t31.0-8\\/s720x720\\/11080657_1015305429020631236239774331416126_o.jpg?oh=7a5e55ce637ddbcbdacb485c5830bbaf&oe=5998BAC0\"},\"picture\":{\"data\":{\"height\":958,\"is_silhouette\":false,\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t1.0-1\\/0.958.958\\/14492344_10154345907211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899\",\"width\":958}},\"id\":\"10154881281451311\"}"}