I am trying to fetch a twitter feed. I am using this URL
https://twitter.com/status/user_timeline/wwwkrcgenkbe.json?count=25&from=wwwkrcgenkbe
This url gives the following JSON Format
[
{
"place": null,
"retweeted": false,
"in_reply_to_status_id_str": null,
"in_reply_to_screen_name": null,
"possibly_sensitive": false,
"in_reply_to_status_id": null,
"truncated": false,
"in_reply_to_user_id_str": null,
"user": { … },
"in_reply_to_user_id": null,
"contributors": null,
"coordinates": null,
"retweet_count": 0,
"favorited": false,
"created_at": "Tue Oct 09 08:54:53 +0000 2012",
"geo": null,
"source": "Facebook",
"id_str": "255592155345727489",
"id": 255592155345727500,
"possibly_sensitive_editable": true,
"text": "Vorige week won Nele Vangeneugden het shirtje dat Jelle Vossen droeg in de Europa League wedstrijd tegen... http://t.co/mwxSsBLP"
},
I am doing it at the following way. First I add this method.
for (NSDictionary *genkInfo in tweets ) {
NSLog(#"Komt in deze methode");
[Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext];
NSLog(#"tweets: %#", tweets);
}
And then I store the values in my core data database at this way.
+ (Twitter *)twitterWithGenkInfo:(NSDictionary *)genkInfo
inManagedObjectContext:(NSManagedObjectContext *)context
{
NSLog(#"till here");
Twitter *twitter= nil;
NSLog(#"till here 2");
twitter = [NSEntityDescription insertNewObjectForEntityForName:#"Twitter"
inManagedObjectContext:context];
NSLog(#"tille here3");
twitter.tweet = [genkInfo objectForKey:TWITTER_TWEET];
twitter.date = [genkInfo objectForKey:TWITTER_DATE];
NSLog(#"till here 4");
NSLog(#"tweet is: %#",twitter.tweet);
NSLog(#"date is: %#",twitter.date);
return twitter;
}
This method is called in my view controller at the following way.
NSArray *tweets = [GenkData getTweets];
for (NSDictionary *genkInfo in tweets ) {
NSLog(#"Komt in deze methode");
[Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext];
}
But I am getting always this error.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 0x2751678'
Can anybody help?
Thanks in advance!
LOG FILE
Log is: (
{
contributors = "<null>";
coordinates = "<null>";
"created_at" = "Tue Oct 09 12:53:08 +0000 2012";
favorited = 0;
geo = "<null>";
id = 255652115341508608;
"id_str" = 255652115341508608;
"in_reply_to_screen_name" = "<null>";
"in_reply_to_status_id" = "<null>";
"in_reply_to_status_id_str" = "<null>";
"in_reply_to_user_id" = "<null>";
"in_reply_to_user_id_str" = "<null>";
place = "<null>";
"possibly_sensitive" = 0;
"possibly_sensitive_editable" = 1;
"retweet_count" = 0;
retweeted = 0;
source = "Facebook";
text = "KRC Genk mobile: de Iphone APP (al meer dan 1 mnd beschikbaar) werd reeds 2226 keer gedownload, de Android APP... http://t.co/QidTcLJS";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Fri Nov 20 18:57:28 +0000 2009";
"default_profile" = 0;
"default_profile_image" = 0;
description = "The official twitter account from Belgian Soccer team KRC Genk. Belgium champions 2011. Qualified for UEFA Euro League 2012-2013.";
"favourites_count" = 1;
"follow_request_sent" = "<null>";
"followers_count" = 4831;
following = "<null>";
"friends_count" = 21;
"geo_enabled" = 0;
id = 91402003;
"id_str" = 91402003;
"is_translator" = 0;
lang = en;
"listed_count" = 94;
location = "Genk - Belgium";
name = "KRC Genk";
notifications = "<null>";
"profile_background_color" = C0DEED;
"profile_background_image_url" = "http://a0.twimg.com/profile_background_images/84123014/youtubebg.jpg";
"profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/84123014/youtubebg.jpg";
"profile_background_tile" = 0;
"profile_image_url" = "http://a0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = wwwkrcgenkbe;
"statuses_count" = 4230;
"time_zone" = "<null>";
url = "http://www.krcgenk.be";
"utc_offset" = "<null>";
verified = 0;
};
},
-[__NSCFNumber managedObjectContext]: unrecognized selector sent to instance 0x9331b40
executeGenkFetch seems to be returning you an empty array, or an array of empty dictionaries.
As #ilmiacs said, post the output of tweets.
Related
let newTodo = [
"currentPageNo" : (page.description) ,
"type": "basic_search",
"searchParams": [
"remember_search" : checkk ,
"u_seeking": (bsMatch_looking) ,
"age_from" : (bsMatch_agefrom) ,
"age_to": (bsMatch_ageto),
"u_looking_for_value" :(bsMatch_lookingfoevalue),
"u_country": (bsMatch_country) ,
"u_state" : (bsMatch_ustate) ,
"u_city": (bsMatch_city) ,
"u_postalcode" : (bsMatch_postelcode) ,
"distance": (bsMatch_distance) ,
]
] as [String : AnyObject]
response is below
["type": basic_search , "currentPageNo": 1 ,"searchParams": {
"age_from" = 18;
"age_to" = 44;
distance = 0;
"remember_search" = On;
"u_city" = "";
"u_country" = 1;
"u_looking_for_value" = 0;
"u_postalcode" = "";
"u_seeking" = Female;
"u_state" = California;
}]
But I want this type of response how can I do this only brasses makes the problem for me please provide me the solution
[{ "currentPageNo": 1, "type": basic_search ,"searchParams": {
"age_from" = 20;
"age_to" = 35;
distance = 100;
"remember_search" = On;
"u_city" = London;
"u_country" = 222;
"u_looking_for_value" = "0";
"u_postalcode" = "";
"u_seeking" = Male;
"u_state" = England;
}}]
I want to convert the first code into the second type
You can order them by having keys with type Int.
var myDictionary: [Int: [String: String]]?
When I'm getting request from google maps API i use this method to get json:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataRequest options: NSJSONReadingAllowFragments error: nil];
jsons look's like this one:
{
routes = (
{
bounds = {
northeast = {
lat = "50.90961";
lng = "20.6492";
};
southwest = {
lat = "50.05775000000001";
lng = "19.94544";
};
};
copyrights = "Dane do Mapy \U00a92012 Google";
legs = (
{
distance = {
text = "126 km";
value = 126118;
};
duration = {
text = "2 godz. 0 min";
value = 7229;
};
"end_address" = "Aleja Powstania Warszawskiego 15, 30-001 Krak\U00f3w, Polska";
"end_location" = {
lat = "50.06";
lng = "19.9589";
};
"start_address" = "Mas\U0142owska 2, 25-001 Kielce, Polska";
"start_location" = {
lat = "50.88884";
lng = "20.6492";
};
steps = (
{
distance = {
text = "0,1 km";
value = 109;
};
duration = {
text = "1 min";
value = 39;
};
"end_location" = {
lat = "50.88824";
lng = "20.64796";
};
"html_instructions" = "Kieruj si\U0119 <b>Mas\U0142owska</b> na <b>po\U0142udniowy zach\U00f3d</b> w stron\U0119 <b>Szyd\U0142\U00f3wek G\U00f3rny</b>";
polyline = {
points = "gfruHo``}BvBvF";
};
"start_location" = {
lat = "50.88884";
lng = "20.6492";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,2 km";
value = 221;
};
duration = {
text = "2 min";
value = 97;
};
"end_location" = {
lat = "50.88896";
lng = "20.64503";
};
"html_instructions" = "Skr\U0119\U0107 <b>w prawo</b> w <b>Szyd\U0142\U00f3wek G\U00f3rny</b>";
polyline = {
points = "obruHwx_}BaCpOMv#";
};
"start_location" = {
lat = "50.88824";
lng = "20.64796";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,6 km";
value = 596;
};
duration = {
text = "1 min";
value = 56;
};
"end_location" = {
lat = "50.88427";
lng = "20.64091";
};
"html_instructions" = "Skr\U0119\U0107 <b>w lewo</b> w <b>Warszawska</b>";
polyline = {
points = "_gruHmf_}BrGvFjQ`OhA|#";
};
"start_location" = {
lat = "50.88896";
lng = "20.64503";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "1,0 km";
value = 950;
};
duration = {
text = "2 min";
value = 104;
};
"end_location" = {
lat = "50.88779";
lng = "20.62863";
};
"html_instructions" = "Skr\U0119\U0107 w drug\U0105 <b>w prawo</b> w kierunku <b>Jesionowa</b>";
polyline = {
points = "uiquHul~|BiEvScCzKs#xCmBhK_#dD}#dIk#tBYr#Mf#Op#MnA";
};
"start_location" = {
lat = "50.88427";
lng = "20.64091";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "4,2 km";
value = 4185;
};
duration = {
text = "5 min";
value = 292;
};
"end_location" = {
lat = "50.90806000000001";
lng = "20.58021";
};
"html_instructions" = "Na rondzie zjazd nr <b>1</b> w <b>\U0141\U00f3dzka</b>";
polyline = {
points = "u_ruH}_||BCd#Cf#?N#RDPHJJHsBzQIl#OrAm#bEEV[vBa#fBUfA_A~Bk#jA}DvGyDpEu#fAsA`C_AhBeAlCmAhDgAnDuAvEwAzFyAvGgA|F]bDH`Ba#fCQjA]tBi#hC}#zDsB|GeBdDwD|Gg#~#cAhBGJ_H`Mo#jAiB`DaAlBcBfD_#`A[fACDuCrMcC`L?#{AhHw#rDiDhPSx#e#dBc#vAa#fAi#jAgCfF{#rAe#p#A#m#p#kBhB";
};
"start_location" = {
lat = "50.88779";
lng = "20.62863";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,2 km";
value = 213;
};
duration = {
text = "1 min";
value = 54;
};
"end_location" = {
lat = "50.90968";
lng = "20.57859";
};
"html_instructions" = "Kontynuuj wzd\U0142u\U017c <b>Trasa 74</b>";
polyline = {
points = "k~uuHiqr|BkBzAiEtEMP";
};
"start_location" = {
lat = "50.90806000000001";
lng = "20.58021";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "92,8 km";
value = 92776;
};
duration = {
text = "1 godz. 17 min";
value = 4641;
};
"end_location" = {
lat = "50.24777";
lng = "20.08501";
};
"html_instructions" = "Skr\U0119\U0107 <b>w lewo</b> w <b>E77</b>";
......
status = OK;
}
Next i use this method to get value for "points" key:
NSArray *items = [jsonArray valueForKeyPath:#"routes.legs.steps.polyline.points"];
When i want to print arrays elements it give only one element (it's strange because i have 25 points in json), and result looks like this one:
(
(
"gfruHo``}BvBvF",
"obruHwx_}BaCpOMv#",
"_gruHmf_}BrGvFjQ`OhA|#",
"uiquHul~|BiEvScCzKs#xCmBhK_#dD}#dIk#tBYr#Mf#Op#MnA",
"u_ruH}_||BCd#Cf#?N#RDPHJJHsBzQIl#OrAm#bEEV[vBa#f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x#lAz#|#p#FB~#v#pA`AdAv#",
"wmspHw|vxBEDKPALCT?pAAbAFhBNZ",
"ymspH_rvxBd#B`BUdCa#n#[ZOHC",
"ubspHcuvxBDC?Ar#Yl#a#|A_BlC_Dl#k#bAiAd#c#`AcAp#s##Ab#]NILIVKf#Kj#AVCVAr#Id#Ez#SLGDCTORQJK#CZc#R_#b#sAT}#d#sBFWLk#NaAJg#",
"q{qpHe}wxBBMh#cF|#cIXuCv#yGPs#\\y#t#q#",
"mrqpHkayxBlCkAlAi#lAo#v#e#t#e#tC{#^InDu#fAW|#GP#r#BdBZxBn#`IfBlAb#fAv#",
"k~opHceyxBd#j#TTPt#FT",
"u{opHu`yxBoBTu#BuHl#o#BI#",
"klppHg~xxBMqFxAI"
)
)
How can i get a normal NSArray with 25 NSString object?
You're looking at the correct output from the polyline field in the JSON. The data is encoded with Google's polyline encoding, which is documented here
https://developers.google.com/maps/documentation/utilities/polylinealgorithm
There are a number of methods online for parsing said string in objective-c, such as this one.
Ok, i have found the solution parsing json with NSJSONSerialization:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataRequest options:NSJSONReadingMutableContainers error: nil];
NSArray * items = [jsonArray valueForKeyPath:#"routes.legs.steps.polyline.points"];
items = [items objectAtIndex:0];
items = [items objectAtIndex:0];
And in items array you will get string with encode direction
I'm trying to parse a nested JSON output like this in Objective C:
{
-Status: {
code: 200
request: "geocode"
name: "1.304044,103.833867"
}
-Placemark: [
-{
-Point: {
-coordinates: [
103.834
1.30396
0
]
}
-AddressDetails: {
-Country: {
CountryName: "Singapore"
-Thoroughfare: {
ThoroughfareName: "Bus stop at Lucky Plaza (09048)"
}
CountryNameCode: "SG"
}
Accuracy: 9
}
id: "p1"
address: "Bus stop at Lucky Plaza (09048)"
}
-{
-Point: {
-coordinates: [
103.834
1.30444
0
]
}
-AddressDetails: {
-Country: {
CountryName: "Singapore"
AddressLine: "Lucky Plaza"
-Thoroughfare: {
-PostalCode: {
PostalCodeNumber: "238863"
}
ThoroughfareName: "304 Orchard Road"
}
CountryNameCode: "SG"
}
Accuracy: 9
}
id: "p2"
address: "Lucky Plaza, 304 Orchard Road, Singapore 238863"
}
-{
-Point: {
-coordinates: [
103.833
1.30376
0
]
}
-AddressDetails: {
-Country: {
CountryName: "Singapore"
AddressLine: "Wisma Atria"
-Thoroughfare: {
-PostalCode: {
PostalCodeNumber: "238877"
}
ThoroughfareName: "435 Orchard Road"
}
CountryNameCode: "SG"
}
Accuracy: 9
}
id: "p3"
address: "Wisma Atria, 435 Orchard Road, Singapore 238877"
}
-{
-Point: {
-coordinates: [
103.835
1.30389
0
]
}
-AddressDetails: {
-Country: {
CountryName: "Singapore"
-Thoroughfare: {
-PostalCode: {
PostalCodeNumber: "238860"
}
ThoroughfareName: "291 Orchard Road"
}
CountryNameCode: "SG"
}
Accuracy: 9
}
id: "p4"
address: "291 Orchard Road, Singapore 238860"
}
-{
-Point: {
-coordinates: [
103.834
1.30491
0
]
}
-AddressDetails: {
-Country: {
CountryName: "Singapore"
AddressLine: "Kimsia Park"
-Thoroughfare: {
-PostalCode: {
PostalCodeNumber: "228968"
}
ThoroughfareName: "1 Jalan Kayu Manis"
}
CountryNameCode: "SG"
}
Accuracy: 9
}
id: "p5"
address: "Kimsia Park, 1 Jalan Kayu Manis, Singapore 228968"
}
]
}
I have some code working, but I'm finding the nested nature of this to be pretty tough to figure out. What I'd like to get out is an array/dictionary which contains the following elements for each return record: coordinates, CountryName, ThoroughfareName, PostalCode and Accuracy.
Here is my test code so far:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *jsonURL = [NSURL URLWithString:#"http://gothere.sg/maps/geo?output=json&ll=1.304044%2C103.833867&client=&sensor=false&callback="];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
self.jsonArray = [jsonData JSONValue];
NSLog(#"%#", jsonArray);
[jsonURL release];
[jsonData release];
}
My code just manages to get the raw JSON output, any thoughts/code to break it down as I've mentioned above.
Thanks!
As requested, some further information.
Using SBJson framework.
NSLog output from above:
2011-08-30 16:44:32.605 Taxi[53070:207] {
Placemark = (
{
AddressDetails = {
Accuracy = 9;
Country = {
CountryName = Singapore;
CountryNameCode = SG;
Thoroughfare = {
ThoroughfareName = "Bus stop at Lucky Plaza (09048)";
};
};
};
Point = {
coordinates = (
"103.834",
"1.30396",
0
);
};
address = "Bus stop at Lucky Plaza (09048)";
id = p1;
},
{
AddressDetails = {
Accuracy = 9;
Country = {
AddressLine = "Lucky Plaza";
CountryName = Singapore;
CountryNameCode = SG;
Thoroughfare = {
PostalCode = {
PostalCodeNumber = 238863;
};
ThoroughfareName = "304 Orchard Road";
};
};
};
Point = {
coordinates = (
"103.834",
"1.30444",
0
);
};
address = "Lucky Plaza, 304 Orchard Road, Singapore 238863";
id = p2;
},
{
AddressDetails = {
Accuracy = 9;
Country = {
AddressLine = "Wisma Atria";
CountryName = Singapore;
CountryNameCode = SG;
Thoroughfare = {
PostalCode = {
PostalCodeNumber = 238877;
};
ThoroughfareName = "435 Orchard Road";
};
};
};
Point = {
coordinates = (
"103.833",
"1.30376",
0
);
};
address = "Wisma Atria, 435 Orchard Road, Singapore 238877";
id = p3;
},
{
AddressDetails = {
Accuracy = 9;
Country = {
CountryName = Singapore;
CountryNameCode = SG;
Thoroughfare = {
PostalCode = {
PostalCodeNumber = 238860;
};
ThoroughfareName = "291 Orchard Road";
};
};
};
Point = {
coordinates = (
"103.83499999999999",
"1.30389",
0
);
};
address = "291 Orchard Road, Singapore 238860";
id = p4;
},
{
AddressDetails = {
Accuracy = 9;
Country = {
AddressLine = "Kimsia Park";
CountryName = Singapore;
CountryNameCode = SG;
Thoroughfare = {
PostalCode = {
PostalCodeNumber = 228968;
};
ThoroughfareName = "1 Jalan Kayu Manis";
};
};
};
Point = {
coordinates = (
"103.834",
"1.30491",
0
);
};
address = "Kimsia Park, 1 Jalan Kayu Manis, Singapore 228968";
id = p5;
}
);
Status = {
code = 200;
name = "1.304044,103.833867";
request = geocode;
};
}
Try this :
//NSMutableArray *addressDetails = [[NSMutableArray alloc] init];
NSMutableArray *addressDetails = [[jsonArray valueForKey:#"Placemark"] valueForKey:#"AddressDetails"];
//NSMutableArray *point = [[NSMutableArray alloc] init];
NSMutableArray *point = [[jsonArray valueForKey:#"Placemark"] valueForKey:#"Point"];
NSLog(#"%#", point);
NSLog(#"%#", [point objectAtIndex:0]);
NSLog(#"%#", addressDetails);
Like wise you can get array of "id" and "address" value also.
To get value of "coordinates" of point array, do this
NSLog(#"%#", [[point objectAtIndex:0] valueForKey:#"coordinates"]);
For AddressDetails/Country/CountryName :
NSLog(#"%#", [[[addressDetails objectAtIndex:0] valueForKey:#"Country"] valueForKey:#"CountryName"]);
Your json is invalid, try to test it on http://jsonviewer.stack.hu/ once it becames valid then only you can use it. You must have used the SBJSON framework to parse it.
I have been trying to retrieve the direct messages and place them into a timeline. I have been successful at doing so, but it is not the way I intended... I am a bit confused and can not seem to find an answer to the issue.
I receive as many direct messages as I want but I have an issue while placing them in a tableview they all show.
If you know a thing or two about twitter the direct messages is a list of users who sent you messages then you click into one and is shows you the actual messages.
So I have tried using just the "user_id" because in a list of items the log returns is shows the user id and that still does the same thing. The user_id , scrren_name, profile_image_url are all sub catagories of the main dictionary "sender" recipient" but when I place those in the table view I just crash.....
Below is how I parse the objets and they work but I caint seem to do what it is supposed to really do
Any help would be very much obliged!
//_______________________________________________________________
// DirecctMessages Parse
//_______________________________________________________________
-(NSString*)sender {
return [contents objectForKey:#"sender"] ;
}
-(NSString*)sender_id {
return [[contents objectForKey:#"sender"] objectForKey:#"sender_id"] ;
}
-(NSString*)sender_screenName {
return [[contents objectForKey:#"sender"] objectForKey:#"screen_name"] ;
}
-(NSString*)sender_profileImage {
return [[contents objectForKey:#"sender"] objectForKey:#"profile_image_url"] ;
}
This is the log
"created_at" = "Fri Jun 17 03:11:25 +0000 2011";
id = 3279750226;
recipient = {
"contributors_enabled" = false;
"created_at" = "Wed Nov 10 10:58:54 +0000 2010";
"default_profile" = false;
"default_profile_image" = false;
description = "Creator of xQuisite HD, Omega HD, AfterHours-HD, BlueBird-HD, ..a web
and IOS5 http://www.youtube.com/user/FreeAppl3";
"favourites_count" = 1;
"follow_request_sent" = false;
"followers_count" = 935;
following = 1;
"friends_count" = 256;
"geo_enabled" = true;
id = 214019964;
"is_translator" = false;
lang = en;
"listed_count" = 23;
location = "From NY 518 in Houston 281";
name = "Anthony Cornell";
notifications = false;
"profile_background_color" = 131516;
"profile_background_image_url" =
"http://a2.twimg.com/profile_background_images/256254613/top-wrapper-bg.jpg";
"profile_background_tile" = true;
"profile_image_url" =
"http://a2.twimg.com/profile_images/1361674958/Wintboard_200px_normal.png";
"profile_link_color" = 0485db;
"profile_sidebar_border_color" = eeeeee;
"profile_sidebar_fill_color" = efefef;
"profile_text_color" = 0896f5;
"profile_use_background_image" = true;
protected = 0;
"screen_name" = FreeAppl3;
"show_all_inline_media" = false;
"statuses_count" = 6166;
"time_zone" = "";
url = "http://idevicethemes.com";
"utc_offset" = "";
verified = false;
};
"recipient_id" = 214019964;
"recipient_screen_name" = FreeAppl3;
sender = {
"contributors_enabled" = false;
"created_at" = "Tue Jul 27 15:12:30 +0000 2010";
"default_profile" = false;
"default_profile_image" = false;
description = "Currently a private platform..The one place all Geeks meet. One place
to call home. We are not building an army. WE are building a Legion. #bAdGB";
"favourites_count" = 12;
"follow_request_sent" = false;
"followers_count" = 699;
following = 0;
"friends_count" = 126;
"geo_enabled" = false;
id = 171526185;
"is_translator" = false;
lang = en;
"listed_count" = 30;
location = "Houston/U.S.A";
name = bAdGB;
notifications = false;
"profile_background_color" = C0DEED;
"profile_background_image_url" =
"http://a3.twimg.com/profile_background_images/154928929/geek.jpg";
"profile_background_tile" = true;
"profile_image_url" =
"http://a2.twimg.com/profile_images/1320730007/ProfilePhoto_normal.png";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = false;
protected = 0;
"screen_name" = bAdGigabit;
"show_all_inline_media" = false;
"statuses_count" = 3088;
"time_zone" = "Central Time (US & Canada)";
url = "http://www.bAdGB.com";
"utc_offset" = "-21600";
verified = false;
};
"sender_id" = 171526185;
"sender_screen_name" = bAdGigabit;
"source_api_request_type" = 13;
text = "Dude. U should add a function to let the user get push updates on a themer he
subscribes too ";
}
Is it because there is no sender_id inside the sender object? Instead try using the id.
{
education = (
{
school = {
id = 108102169223234;
name = psss;
};
type = College;
year = {
id = 142833822398097;
name = 2010;
};
}
);
email = "amvijaycse#gmail.com";
"first_name" = Vijay;
gender = male;
id = 100000782204693;
"last_name" = Kumar;
link = "http://www.facebook.com/profile.php?id=100000782204693";
locale = "en_US";
location = {
id = 106377336067638;
name = "Bangalore, India";
};
name = "Vijay Kumar";
timezone = "5.5";
"updated_time" = "2010-11-21T07:45:11+0000";
}
i needed email,firstname,lastname.
[EDIT: Removed because it was inaccurate]