Twitter Direct Messages - iPhone - iphone

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.

Related

get_value of a feature in IFeatureCursor

I'm trying to read the attribute "POSTCODE" of the features in IFeatureCursor. The FID was successful read but the "POSTCODE" was failed. The runtime error 'An expected Field was not found or could not be retrieved properly. Appreciate your advise. Paul
private void test2(IFeatureCursor pFeatc1)
{
IFeature feature = null;
IFields pFields;
int ctcur = 0;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indxid = pFields.FindField("FID");
int indxpost = pFields.FindField("POSTCODE");
object valu = feature.get_Value(indxid);
string valupost = feature.get_Value(indxpost);
string aValu = Convert.ToString(valu);
Debug.WriteLine("FID: " + aValu + " Postcode: " + valupost);
ctcur++;
feature = pFeatc1.NextFeature();
}
MessageBox.Show("count cursor = " + ctcur);
}
I have modified the program and successfully read the feature attribute 'POSTCODE'. I have added IFeatureClass.Search(queryFilter, true) to search the feature again by FID and save in a cursor then use the 'feature.get_Value' to read the attribute. Please see my updated code below. Thanks.
private void test2(IFeatureCursor pFeatc1)
{
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap;
IFeatureLayer flayer;
IMaps pMaps = mxdoc.Maps;
for (int i = 0; i <= pMaps.Count - 1; i++)
{
map = pMaps.get_Item(i);
IEnumLayer pEnumLayer = map.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
if (pLayer.Name == "AddrKey")
{
Debug.WriteLine("Layer: " + pLayer.Name);
flayer = (IFeatureLayer)pLayer;
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeature feature = null;
IFields pFields;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indx = pFields.FindField("FID");
object valu = feature.get_Value(indx);
string sFID = Convert.ToString(valu);
IQueryFilter queryFilter = new QueryFilter();
queryFilter.WhereClause = ("FID = " + sFID);
Debug.WriteLine("FID: " + sFID);
queryFilter.SubFields = "POSTCODE";
int fieldPosition = pFeatureClass.FindField("POSTCODE");
IFeatureCursor featureCursor = pFeatureClass.Search(queryFilter, true);
while ((feature = featureCursor.NextFeature()) != null)
{
MessageBox.Show(feature.get_Value(fieldPosition));
}
feature = pFeatc1.NextFeature();
}
}
pLayer = pEnumLayer.Next();
}
}
}

Swift accessing key from dictionary returning null

I have a dictionary. When I try to access that dictionary, it is returning a null value when it should definately be returning an actual value. I'm stumped. Any help is always appreciated.
if let d = response.result.value {
print(d) //prints correct data
let prices = d["prices"] as? [[String:AnyObject?]]
print(prices) //prints nil
let best_price = prices?[0]
let price = best_price?["price"] as? String
print(price) //prints nil
}
Console:
{
item = {
"item_number" = 57;
image = "http://example.com/tent.jpg";
name = "Small Red Tent";
};
prices = (
{
link = "http://example.com/id=19";
price = "58.15";
rating = "3.64";
"vendor_id" = 50;
},
{
link = "http://example.com/id=50";
price = "58.14";
rating = "5.00";
"vendor_id" = 110;
},
{
link = "http://example.com/id=26";
price = "50.40";
rating = "4.71";
"vendor_id" = 73;
},
{
link = "http://example.com/id=12";
price = "47.16";
rating = "4.00";
"vendor_id" = 1;
},
{
link = "http://example.com/id=13";
price = "45.75";
rating = "3.90";
"vendor_id" = 25;
},
{
link = "http://example.com/id=16";
price = "41.32";
rating = "3.02";
"vendor_id" = 16;
},
{
link = "http://example.com/id=1";
price = "36.59";
rating = "4.84";
"vendor_id" = 51;
},
{
link = "http://example.com/id=2";
price = "36.29";
rating = "3.26";
"vendor_id" = 43;
},
{
link = "http://example.com/id=13";
price = "34.59";
rating = "4.14";
"vendor_id" = 48;
},
{
link = "http://example.com/id=3";
price = "32.00";
rating = "4.29";
"vendor_id" = 53;
},
{
link = "http://example.com/id=4";
price = "24.50";
rating = "4.16";
"vendor_id" = 8;
},
{
link = "http://example.com/id=5";
price = "15.00";
rating = "4.87";
"vendor_id" = 39;
},
{
link = "http://example.com/id=6";
price = "0.00";
rating = "3.00";
"vendor_id" = 65;
}
);
}
nil
nil
So the solution was proposed by Larme solved the problem.
let prices = d["prices"] as? [AnyObject]
Although I never figured out why casting d["prices"] as? [[String:AnyObject?]] wouldn't also work.

fetching data from twitter api

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.

objectAtIndex in NSDictionary

I am trying to create UITableView from my NSDictionary, but how can I use objectForKey? Convert to NSArray?
I need help.
My dictionary looks like:
**
{
"allow_comments" = 1;
category = 1024194;
"created_at" = "2011-11-17T01:44";
forum = 1005401;
"forum_obj" = {
"created_at" = "2011-09-03 03:04:43.514514";
description = "";
id = 1005401;
name = smartfiction;
shortname = smartfiction;
};
hidden = 0;
id = 474530565;
identifier = (
"2507 http://smartfiction.ru/?p=2507"
);
"num_comments" = 2;
slug = "thread_9714";
title = "\U041e\U0440\U0438\U0444\U043b\U0430\U043c\U043c\U0430. \U042d\U0436\U0435\U043d \U0418\U043e\U043d\U0435\U0441\U043a\U043e";
url = "http://smartfiction.ru/prose/oriflamma/";
}
2011-11-19 10:21:25.992 ARSSReader[3067:15503] id 474530565
2011-11-19 10:21:26.864 ARSSReader[3067:15503] Ответ #2: (
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = af6c6f08e213427ad611b00589db00f9;
isAnonymous = 1;
name = "S Shv";
profileUrl = "http://disqus.com/guest/af6c6f08e213427ad611b00589db00f9/";
url = "";
};
createdAt = "2011-11-17T22:39:36";
dislikes = 0;
forum = smartfiction;
id = 367003621;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 0;
media = (
);
message = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
parent = "<null>";
points = 0;
"raw_message" = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
thread = 474530565;
},
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = c1c53088e04a60aab74cd1f149117e69;
isAnonymous = 1;
name = "3,14";
profileUrl = "http://disqus.com/guest/c1c53088e04a60aab74cd1f149117e69/";
url = "";
};
createdAt = "2011-11-17T02:52:46";
dislikes = 0;
forum = smartfiction;
id = 365544459;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 1;
media = (
);
message = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
parent = "<null>";
points = 1;
"raw_message" = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
thread = 474530565;
}
)
**
It is comments from disqus.com. I want to create dictionaries for all comments and use them to create UITableView cells.
Instead of storing the comments from disqus.com in a dictionary, store each comment in an entry inside an array (it looks like each comment has a block of text you can encapsulate into an object which you can store into an array).
Dictionaries are good for associating values with keys.
Arrays are great for storing lists of objects, much like a list of comments from a disqus site.

how to parse this in iphone

{
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]