I want to access array of friends for facebook.so for this i am using FBGraph and i get a string
by this line
NSString *str=(NSString *)fb_graph_response.htmlResponse;
so response is
getMeFriendsButtonPressed: {"data":[{"name":"R.B. Narain","id":"1452788"},{"name":"Jon doe","id":"6564709"}]}
now i wanna get array of friends so for this what can i do.
It is JSON response...... you will need JSON parsing..... For this, either you can write your own parser..... or you can use exising one http://code.google.com/p/json-framework/
thanks.
Related
How can I get the permalink_url only of using Soundcloud API tracks?
It returns all fields.
How am I able to return only the permalink_url?
I tried this but no luck: I tried this but no luck: http://api.soundcloud.com/tracks.json?client_id=XX&q=Charlie%20Puth&limit=100&fields=permalink_url
You should be able to parse the returned JSON for the permalink_url. Something like:
var parsedJSON = JSON.parse(tracksJSON);
var permalink = parsedJSON.permalink_url;
If you have jQuery, I believe $.getJSON automatically parses the info for you as well. I hope this helps you!
Does anyone have any idea how to fetch profile picture and first + last name of Facebook member by his profile link/ID without authorising app or anything.
You can retrieve that data from following URL:-
https://graph.facebook.com/USERNAMEORID?fields=id,name,first_name,last_name,picture
Replace "USERNAMEORID" to fb username or id of specified user.
You can fetch these data as following:-
<?php
$content = file_get_contents('https://graph.facebook.com/myid?fields=id,name,first_name,last_name,picture');
$content = json_decode($content, true);
print_r($content); // <- this print data as associative array, You can fetch it and get data
?>
I added a json_decode function to your code whereas the data coming form facebook graph is json format, So i used that function to convert json format to object, Then i used true parameter to make this object as associative array. Now you can fetch this array normally as any array.
If you need anything else tell me, I'll be happy to help.
I would like to be able to create an NSArray or NSDictionary with a JSON string that I receive from a web service. I am using the json framework to do this. The response string will look something along these lines:
{count:2,
data:[{"ID":8,
"Title":"Test Title",
"Author":"Test Author",
"Price":"18.00",
"Edition":"1st",
"Condition":"Good",
"UploadDate":"2012-07-28 07:25:56.0"
},
{"ID":9,
"Title":"Test Title",
"Author":"Test Author",
"Price":"18.000000000000",
"Edition":"1st",
"Condition":"Good",
"UploadDate":"2012-07-28 07:27:06.0"
}
]
}
My question is, what is the most efficient way to grab all of the data from the 'data' array and use it to create either an NSArray or NSDictionary? Any help would be much appreciated
I use RestKit for JSON parsing. It has all you need to fetch the json from a server, translate it into a dictionary, and from there into an object that you can work with. That might be more than you dared to wish for, but it works like a charm. Check out https://github.com/RestKit/RestKit for more info.
Starting from iOS5 a json parser has been integrated as a SDK native component see the following link http://www.raywenderlich.com/5492/working-with-json-in-ios-5.
You will create a NSDictionary with 2 keys "count" and "data" and then you will get the NSArray using objectForKey with the "data" key.
I am using Facebook graph api to retrieve facebook's friend list.
I'm using this code:
-(IBAction)getMeFriendsButtonPressed:(id)sender
{
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/friends" withGetVars:nil];
NSLog(#"getMeFriendsButtonPressed: %#", fb_graph_response.htmlResponse);
}
And in return I am getting this at console.
getMeFriendsButtonPressed:
{"data":[{"name":"name1","id":"504181912"},
{"name":"name2","id":"505621879"},
{"name":"name3","id":"520845156"},
{"name":"name4","id":"537539375"}
}
or something like this.
I want to get names, like name1, name2, name3 and show it in table view.
How can I create an array of these name?
Suggestion please
Thanks
This is JSON output. You may refer to the JSON parsing tutorial at this link
http://www.xprogress.com/post-44-how-to-parse-json-files-on-iphone-in-objective-c-into-nsarray-and-nsdictionary/
Hope this works for you.
The respone your are getting is JSON. You should use JSON parser for parsing the JSON String
JSON Framework
I am using FConnect in my app. After the user logs in to his/her Facebook account I am getting his/her information as:
{
"id":"###########",
"name":"Vishnu Gupta",
"first_name":"Vishnu",
"last_name":"Gupta",
"link":"facebook a/c link id=#######",
"education":[{"school":{"id":"######","name":"st.joseph"},"type":"High School"}],
"gender":"male","email":"##########",
"timezone":5.5,
"locale":"en_US",
"verified":true,
"updated_time":"2010-11-27T10:10:25+0000"
}
I want to store user's information in database. To do that, I have to separate the user's information that is id, name, and email.
I tried using componentsSeparatedByString method but I do not understand how to retrieve the information in an array.
Can anyone help me????
The response you are getting is in JSON Format which basically have response in Array & Dictionary.
You will be getting this data in Dictionary..so you can access it by using the key value..
NSLog(#"%#",[NSDictionaryObject valueforkey:#"id"]);
NSLog(#"%#",[NSDictionaryObject valueforkey:#"name"]);
NSLog(#"%#",[NSDictionaryObject valueforkey:#"first_name"]);
Hope this will surely work for you.....
ya.....its corrrect.In detail:
Add JSON SDK then write the below code
SBJSON *json = [[SBJSON alloc] init];
NSDictionary *returnObject = [json objectWithString:InfoName];
NSString #id=[NSString stringWithFormat:#"%#",[returnObject objectForKey:#"id"]];
same for name ,email.
then Add these objects to Array and release the json
JSOn is good to use for "key-value' pair parsing.