admin管理员组文章数量:1325236
function getUser()
{
FB.api('/me', function(response) {
console.log('Response is '+response);
alert('Your name is ' + response.first_name);
alert('Your last name is ' + response.last_name);
alert('Your Gender is ' + response.gender);
alert('Your status is '+response.username);
}
How can I get the entire response like this below printed?
{
"id": "blah blah",
"name": "blah blah",
"first_name": "blah blah",
"last_name": "blah blah",
"link": " blah",
"username": "blah blah",
"hometown": {
"id": "106442706060302",
"name": "Pune, Maharashtra"
},
"location": {
"id": "106377336067638",
"name": "Bangalore, India"
},
"bio": "╔══╗♫ ♪♫\n║██║\n║¨o•♫\n╚═|̲̅̅●̲̅̅|̅lιlllι ♫ I LoVe MuZiK!!\n\n█║▌│█│║▌║│█║▌│║\n® Copyright © 2012 ™\n█║▌│█│║▌║│█║▌│║\n\nReVoLt",
"gender": "male",
"relationship_status": "Single",
"timezone": 5.5,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-06-15T05:33:31+0000",
"type": "user"
}
Also by respose.name am getting the name of the user. How can I get the location in the parameter location as it is a JSON array?
function getUser()
{
FB.api('/me', function(response) {
console.log('Response is '+response);
alert('Your name is ' + response.first_name);
alert('Your last name is ' + response.last_name);
alert('Your Gender is ' + response.gender);
alert('Your status is '+response.username);
}
How can I get the entire response like this below printed?
{
"id": "blah blah",
"name": "blah blah",
"first_name": "blah blah",
"last_name": "blah blah",
"link": "https://www.facebook./blah blah",
"username": "blah blah",
"hometown": {
"id": "106442706060302",
"name": "Pune, Maharashtra"
},
"location": {
"id": "106377336067638",
"name": "Bangalore, India"
},
"bio": "╔══╗♫ ♪♫\n║██║\n║¨o•♫\n╚═|̲̅̅●̲̅̅|̅lιlllι ♫ I LoVe MuZiK!!\n\n█║▌│█│║▌║│█║▌│║\n® Copyright © 2012 ™\n█║▌│█│║▌║│█║▌│║\n\nReVoLt",
"gender": "male",
"relationship_status": "Single",
"timezone": 5.5,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-06-15T05:33:31+0000",
"type": "user"
}
Also by respose.name am getting the name of the user. How can I get the location in the parameter location as it is a JSON array?
Share Improve this question edited Jun 27, 2012 at 11:44 dominic asked Jun 16, 2012 at 8:44 dominicdominic 3183 gold badges6 silver badges17 bronze badges3 Answers
Reset to default 2use JSON.stringify(response); it should print the entire object.
use JSON.parse() or jQuery.parseJSON(); to parse and get any properties of the response object examples here : jsfiddle/epinapala/HrfkL and here : jsfiddle/epinapala/zfWWv/3
var obj2 = JSON.parse('{"id":"579156356","name":"Vishal Jethani","first_name":"Vishal","last_name":"Jethani","link":"https://www.facebook./vishal.jethani","username":"vishal.jethani","hometown":{"id":"106442706060302","name":"Pune, Maharashtra"},"location":{"id":"106377336067638","name":"Bangalore, India"},"bio":"bye bye to bad characters","gender":"male","relationship_status":"Single","timezone":5.5,"locale":"en_GB","verified":true,"updated_time":"2012-06-15T05:33:31+0000","type":"user"}');
alert("Parsing with Json : " + obj2.location.name);
For multidimensional array as asked by the requester : THis should work : http://jsfiddle/epinapala/WQcDg/
var obj2 = JSON.parse('{"work":[{"employer":{"id":"185998961446429","name":"Pvt Ltd"}}]}');
alert("Parsing with Json : " + JSON.stringify(obj2.work[0].employer.name));
i think you have to use FB Graph api. and if you want more information then you have to use like this
https://graph.facebook./579156356
https://graph.facebook./btaylor?access_token=AAAAAAITEghMBAHTRFEKjKcvFe1W2NJTu1Gsy20cNWEe0Dh98KoOhJEInZB1kXrMprNUaN6nq8FZA7YMZBvNVLwuz6pglh1SIBbZCnEECOAZDZD
i am useing like this.
function(evt){
console.log(evt.target.responseText);
var FB_obj = JSON.parse(evt.target.responseText);
console.log("fb id >>"+FB_obj.id);
console.log("fb name >>"+FB_obj.name);
}
Use Jquery get Json method isted using pure javascript,
- You need to get Accesstoken
- Replace your access token below the texted YOUR_ACCESS_TOKEN field
I used this library to get the date formatted, https://github./datejs/Datejs
$.getJSON("https://graph.facebook./5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=4",
function(result){
for(x = 0; x < result.data.length; x++) {
var id = result.data[x].id;
var name = result.data[x].name;
var cover = result.data[x].cover.source;
var date = new Date(result.data[x].start_time);
var place = result.data[x].place.name;
var day = date.toString('dd');
var month = date.toString('MMM');
var url = 'https://facebook./'+id;
var time = date.toString("hh:mm tt");
$("#evt").append(name);
}
});
本文标签: Facebook API Javascript JSON responseStack Overflow
版权声明:本文标题:Facebook API Javascript JSON response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742166243a2425878.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论