Where are an UIWebView's cookies stored? - iphone

I'm building an iPhone app with cookies. Deleting cookies in the Safari settings doesn't delete them. Where are they stored? Is it possible to read them from another UIWebView?
Thanks!

Your application has its own "cookie jar" in the [NSHTTPCookieStorage sharedHTTPCookieStorage] container.
Here's how you might take a quick look at the cookies in your application's cookie jar:
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
NSLog(#"%#", cookie);
}
Several methods are available for filtering and manipulation. Take a look at the NSHTTPCookieStorage documentation for accessing cookies, and the NSHTTPCookie documentation for accessing individual cookie properties.

Thanks for the pointer Alex! To add to this I will drop in my "cookie dumper" that I created using Alex's example. Maybe this will help someone else.
- (void) dumpCookies:(NSString *)msgOrNil {
NSMutableString *cookieDescs = [[[NSMutableString alloc] init] autorelease];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
[cookieDescs appendString:[self cookieDescription:cookie]];
}
NSLog(#"------ [Cookie Dump: %#] ---------\n%#", msgOrNil, cookieDescs);
NSLog(#"----------------------------------");
}
- (NSString *) cookieDescription:(NSHTTPCookie *)cookie {
NSMutableString *cDesc = [[[NSMutableString alloc] init] autorelease];
[cDesc appendString:#"[NSHTTPCookie]\n"];
[cDesc appendFormat:#" name = %#\n", [[cookie name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:#" value = %#\n", [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:#" domain = %#\n", [cookie domain]];
[cDesc appendFormat:#" path = %#\n", [cookie path]];
[cDesc appendFormat:#" expiresDate = %#\n", [cookie expiresDate]];
[cDesc appendFormat:#" sessionOnly = %d\n", [cookie isSessionOnly]];
[cDesc appendFormat:#" secure = %d\n", [cookie isSecure]];
[cDesc appendFormat:#" comment = %#\n", [cookie comment]];
[cDesc appendFormat:#" commentURL = %#\n", [cookie commentURL]];
[cDesc appendFormat:#" version = %d\n", [cookie version]];
// [cDesc appendFormat:#" portList = %#\n", [cookie portList]];
// [cDesc appendFormat:#" properties = %#\n", [cookie properties]];
return cDesc;
}

Alex had a great idea about putting this in a category. Here's what I ended up using:
NSHTTPCookieStorage+Info.h
#import <Foundation/Foundation.h>
#interface NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies;
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie;
#end
NSHTTPCookieStorage.m
#implementation NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies {
NSMutableDictionary *descriptions = [NSMutableDictionary new];
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] enumerateObjectsUsingBlock:^(NSHTTPCookie* obj, NSUInteger idx, BOOL *stop) {
[descriptions setObject:[[self class] describeCookie:obj] forKey:[[obj name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}];
NSLog(#"Cookies:\n\n%#", descriptions);
return descriptions;
}
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie {
return #{#"value" : [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
#"domain" : [cookie domain] ? [cookie domain] : #"n/a",
#"path" : [cookie path] ? [cookie path] : #"n/a",
#"expiresDate" : [cookie expiresDate] ? [cookie expiresDate] : #"n/a",
#"sessionOnly" : [cookie isSessionOnly] ? #1 : #0,
#"secure" : [cookie isSecure] ? #1 : #0,
#"comment" : [cookie comment] ? [cookie comment] : #"n/a",
#"commentURL" : [cookie commentURL] ? [cookie commentURL] : #"n/a",
#"version" : #([cookie version]) };
}
#end
Makes the output a bit more "JSON-y"...

in sandbox:Library->Cookies->Cookies.binarycookies
but you can not open the .binarycookies directly, you can run a script:
Download and install Python
Download BinaryCookieReader.py
Run "Python BinaryCookieReader.py" on the terminal
as you can see, output log contains detail cookies description

Related

Core data do not fetch record

i added website field in core data after adding other attributes to xcdatamodel, and i am saving this attribute like this
- (void)fetchandSaveGWTGsSince:(NSString *)since
{
NSString *completeURL = [NSString stringWithFormat:#"%#api.php?action=get_all_gwtgs&sinceDate=%#", BASE_URL, since];
NSURL *url = [NSURL URLWithString:completeURL];
// self.loggingEnable = NO;
if (self.loggingEnable == YES)
{
NSLog(#"%#", [NSString stringWithFormat:#"%i", [since integerValue]-18000]);
NSLog(#"%#", since);
NSLog(#"%#", [[NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[since integerValue]] description]);
NSLog(#"%#", [[NSDate dateWithTimeIntervalSince1970:((NSTimeInterval)[since integerValue])-18000] description]);
NSLog(#"%#", completeURL);
}
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.timeoutInterval = REQUEST_TIMEOUT;
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:#"text/html"]];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSDictionary *resDict = (NSDictionary *)JSON;
if (self.loggingEnable == YES)
{
NSLog(#"Response GWTGs : %#", resDict);
}
if ([[resDict objectForKey:#"status"] isEqualToString:#"success"])
{
NSArray *data = [[resDict objectForKey:#"data"] objectAtIndex:0];
NSManagedObjectContext *context = [[Common apd] managedObjectContext];
if ([data count] > 0)
{
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary *gwtgDict = (NSDictionary *)obj;
if ([gwtgDict objectForKey:#"gwtg_id"])
{
NSArray *locationInfos = [self getGWTGsWithGWTG_ID:[gwtgDict objectForKey:#"gwtg_id"]];
if ([locationInfos count] > 0)
{
for (Location *location in locationInfos)
{
[context deleteObject:location];
NSError *error = nil;
if (![context save:&error]) {
// Handle the error.
if (self.loggingEnable == YES)
{
NSLog(#"error deleting gwtg : %#", [location description]);
}
}
}
}
}
}];
}
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary *gwtgInfo = (NSDictionary *)obj;
/*
gwtg_status = 0 => Inactive Record
gwtg_status = 1 => New Record/Active Record
gwtg_status = 2 => Updated Record
gwtg_status = 3 => Deleted Record
*/
if ([[gwtgInfo objectForKey:#"gwtg_status"] intValue] != 3)
{
GWTG *gwtg = [NSEntityDescription insertNewObjectForEntityForName:#"GWTG" inManagedObjectContext:context];
gwtg.gwtg_id = ([[gwtgInfo objectForKey:#"gwtg_id"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"gwtg_id"];
NSData *celData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"celebrity_name"]];
NSString *celName = [[NSString alloc] initWithData:celData encoding:NSStringEncodingConversionAllowLossy];
gwtg.celebrity_name = ([celName isKindOfClass:[NSNull class]]) ? #"" : celName;
gwtg.location_id = ([[gwtgInfo objectForKey:#"location_id"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"location_id"];
NSData *loc_cityData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"location_city"]];
NSString *loc_cityName = [[NSString alloc] initWithData:loc_cityData encoding:NSStringEncodingConversionAllowLossy];
gwtg.location_city = ([loc_cityName isKindOfClass:[NSNull class]]) ? #"" : loc_cityName;
NSData *cityData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"city"]];
NSString *cityName = [[NSString alloc] initWithData:cityData encoding:NSStringEncodingConversionAllowLossy];
gwtg.city = ([cityName isKindOfClass:[NSNull class]]) ? #"" : cityName;
NSData *stateData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"state"]];
NSString *stateName = [[NSString alloc] initWithData:stateData encoding:NSStringEncodingConversionAllowLossy];
gwtg.state = ([stateName isKindOfClass:[NSNull class]]) ? #"" : stateName;
NSData *countryData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"country"]];
NSString *countryName = [[NSString alloc] initWithData:countryData encoding:NSStringEncodingConversionAllowLossy];
gwtg.country = ([countryName isKindOfClass:[NSNull class]]) ? #"" : countryName;
gwtg.a_consuming = ([[gwtgInfo objectForKey:#"a_consuming"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"a_consuming"];
gwtg.a_playing = ([[gwtgInfo objectForKey:#"a_playing"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"a_playing"];
gwtg.a_lodging = ([[gwtgInfo objectForKey:#"a_lodging"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"a_lodging"];
gwtg.a_shopping = ([[gwtgInfo objectForKey:#"a_shopping"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"a_shopping"];
gwtg.a_recommending = ([[gwtgInfo objectForKey:#"a_recommending"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"a_recommending"];
gwtg.w_g_here = ([[gwtgInfo objectForKey:#"w_g_here"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"w_g_here"];
NSData *locData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"location_name"]];
NSString *locName = [[NSString alloc] initWithData:locData encoding:NSStringEncodingConversionAllowLossy];
gwtg.location_name = ([locName isKindOfClass:[NSNull class]]) ? #"" : locName;
//location_address, we_go_here, credit
NSData *locAdData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"location_address"]];
NSString *locAdName = [[NSString alloc] initWithData:locAdData encoding:NSStringEncodingConversionAllowLossy];
gwtg.location_address = ([locAdName isKindOfClass:[NSNull class]]) ? #"" : locAdName;
gwtg.location_phone = ([[gwtgInfo objectForKey:#"location_phone"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"location_phone"];
gwtg.location_zip_code = ([[gwtgInfo objectForKey:#"location_zip_code"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"location_zip_code"];
NSData *wghData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"we_go_here"]];
NSString *wghName = [[NSString alloc] initWithData:wghData encoding:NSStringEncodingConversionAllowLossy];
gwtg.we_go_here = ([wghName isKindOfClass:[NSNull class]]) ? #"" : wghName;
gwtg.wgh_date = ([[gwtgInfo objectForKey:#"wgh_date"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"wgh_date"];
NSData *creData = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"credit"]];
NSString *creName = [[NSString alloc] initWithData:creData encoding:NSStringEncodingConversionAllowLossy];
gwtg.credit = ([creName isKindOfClass:[NSNull class]]) ? #"" : creName;
NSData *webSite_Data = [NSData dataWithBase64EncodedString:[gwtgInfo objectForKey:#"website"]];
NSString *add_website = [[NSString alloc] initWithData:webSite_Data encoding:NSStringEncodingConversionAllowLossy];
gwtg.website = ([add_website isKindOfClass:[NSNull class]]) ? #"" : add_website;
gwtg.gwtg_status = ([[gwtgInfo objectForKey:#"gwtg_status"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"gwtg_status"];
gwtg.gwtg_isactive = ([[gwtgInfo objectForKey:#"gwtg_isactive"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"gwtg_isactive"];
gwtg.addeddate = ([[gwtgInfo objectForKey:#"addeddate"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"addeddate"];
gwtg.modifieddate = ([[gwtgInfo objectForKey:#"modifieddate"] isKindOfClass:[NSNull class]]) ? #"" : [gwtgInfo objectForKey:#"modifieddate"];
if (self.loggingEnable == YES)
{
NSLog(#"----Location----");
NSLog(#"%#", gwtg.gwtg_id);
NSLog(#"%#", gwtg.celebrity_name);
NSLog(#"%#", gwtg.location_id);
NSLog(#"%#", gwtg.city);
NSLog(#"%#", gwtg.state);
NSLog(#"%#", gwtg.country);
NSLog(#"%#", gwtg.a_consuming);
NSLog(#"%#", gwtg.a_playing);
NSLog(#"%#", gwtg.a_lodging);
NSLog(#"%#", gwtg.a_shopping);
NSLog(#"%#", gwtg.a_recommending);
NSLog(#"%#", gwtg.w_g_here);
NSLog(#"%#", gwtg.location_name);
NSLog(#"%#", gwtg.location_address);
NSLog(#"%#", gwtg.location_phone);
NSLog(#"%#", gwtg.location_zip_code);
NSLog(#"%#", gwtg.we_go_here);
NSLog(#"%#", gwtg.wgh_date);
NSLog(#"%#", gwtg.credit);
NSLog(#"%#", gwtg.website);
NSLog(#"%#", gwtg.gwtg_status);
NSLog(#"%#", gwtg.addeddate);
NSLog(#"%#", gwtg.modifieddate);
NSLog(#"%#", gwtg.gwtg_isactive);
}
NSError *error;
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
}
}];
if ([[NSUserDefaults standardUserDefaults] objectForKey:LAST_TIME_GWTG_UPDATED])
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:LAST_TIME_GWTG_UPDATED];
}
NSDate *date = [NSDate date];
NSLog(#"date last time : %#", [data description]);
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:#"%.f", [date timeIntervalSince1970]] forKey:LAST_TIME_GWTG_UPDATED];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationRequestFinished object:nil userInfo:nil];
}
else
{
// [Common showAlertWithTitle:#"Warning" message:[resDict objectForKey:#"message"]];
if ([[NSUserDefaults standardUserDefaults] objectForKey:LAST_TIME_GWTG_UPDATED])
{
}
else
{
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:#"0"] forKey:LAST_TIME_GWTG_UPDATED];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
if (self.loggingEnable == YES)
{
NSLog(#"error %#", [error description]);
}
[Common showAlertWithTitle:#"Error Retrieving" message:[NSString stringWithFormat:#"%#",[error localizedDescription]]];
if ([[NSUserDefaults standardUserDefaults] objectForKey:LAST_TIME_GWTG_UPDATED])
{
}
else
{
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:#"0"] forKey:LAST_TIME_GWTG_UPDATED];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}];
[operation start];
}
and i am getting website url like this, but it always come empty,
NSString *urlString = [NSString stringWithFormat:#"%#", _gwtgDO.website];
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
why it is always empty although i am getting website link from server correctly? is this due to reason that i added attribute later? what should i do now?
You are passing NSStringEncodingConversionOptions instead of NSStringEncoding. I suppose you want NSString *add_website = [[NSString alloc] initWithData:webSite_Data encoding:NSUTF8StringEncoding]; for UTF-8 encoding, for example.
More about the encodings here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

how to capture the required values from a URL

I need to extract a variable's value from a string, which happens to be a URL. The string/url is loaded as part of a separate php query, not the url in the browser.
The url's will look like:
http://gmail.com?access_token=ab8w4azq2xv3dr4ab37vvzmh&token_type=bearer&expires_in=3600
How can I capture the value of the access_token which in this example is ab8w4azq2xv3dr4ab37vvzmh?
This code should do it:
- (NSString *)extractToken:(NSURL *)URL
{
NSString *urlString = [URL absoluteString];
NSRange start = [urlString rangeOfString:#"access_token="];
if (start.location != NSNotFound)
{
NSString *token = [urlString substringFromIndex:start.location+start.length];
NSRange end = [token rangeOfString:#"&"];
if (end.location != NSNotFound)
{
//trim off other parameters
token = [token substringToIndex:end.location];
}
return token;
}
//not found
return nil;
}
Alternatively, here is a more general solution that will extract all the query parameters into a dictionary:
- (NSDictionary *)URLQueryParameters:(NSURL *)URL
{
NSString *queryString = [URL query];
NSMutableDictionary *result = [NSMutableDictionary dictionary];
NSArray *parameters = [queryString componentsSeparatedByString:#"&"];
for (NSString *parameter in parameters)
{
NSArray *parts = [parameter componentsSeparatedByString:#"="];
NSString *key = [[parts objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([parts count] > 1)
{
id value = [[parts objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[result setObject:value forKey:key];
}
}
return result;
}
Good Category for NSDictionary:
#import "NSDictionary+URL.h"
#implementation NSDictionary (URL)
+ (NSDictionary *)dictionaryWithUrlString:(NSString *)urlString{
NSRange urlRange = [urlString rangeOfString:#"?"];
if(urlRange.length>0){
urlString = [urlString substringFromIndex:urlRange.length+urlRange.location];
}
NSArray *pairsArray = [urlString componentsSeparatedByString:#"&"];
NSMutableDictionary *parametersDictionary = [[NSMutableDictionary alloc] initWithCapacity:[pairsArray count]];
for(NSString *pairString in pairsArray){
NSArray *valuesArray = [pairString componentsSeparatedByString:#"="];
if([valuesArray count]==2){
[parametersDictionary setValue:[valuesArray objectAtIndex:1] forKey:[valuesArray objectAtIndex:0]];
}
}
return [parametersDictionary autorelease];
}
#end
NSMutableDictionary *querycomponent = [[NSMutableDictionary alloc] init];
if (![query isEqualToString:#""]){
NSArray *queryArray = [query componentsSeparatedByString:#"&"];
for (NSString *subquery in queryArray){
NSArray *subqueryArray = [subquery componentsSeparatedByString:#"="];
NSString *key = [subqueryArray objectAtIndex:0];
NSString *val = [subqueryArray objectAtIndex:1];
[querycomponent setObject:val forKey:key];
}
NSLog(#"querycomponent %#",querycomponent);
}

problem submitting tweet to twitter from iphone

MGTwitterEngine.m
- (NSString *)username
{
return [[_username retain] autorelease];
}
- (NSString *)password
{
return [[_password retain] autorelease];
}
- (void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
// Set new credentials.
[_username release];
_username = [newUsername retain];
[_password release];
_password = [newPassword retain];
if ([self clearsCookies]) {
// Remove all cookies for twitter, to ensure next connection uses new credentials.
NSString *urlString = [NSString stringWithFormat:#"%#://%#",
(_secureConnection) ? #"https" : #"http",
_APIDomain];
NSURL *url = [NSURL URLWithString:urlString];
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSEnumerator *enumerator = [[cookieStorage cookiesForURL:url] objectEnumerator];
NSHTTPCookie *cookie = nil;
while (cookie == [enumerator nextObject]) {
[cookieStorage deleteCookie:cookie];
}
}
}
- (NSString *)sendUpdate:(NSString *)status
{
return [self sendUpdate:status inReplyTo:0];
}
- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
if (!status) {
return nil;
}
NSString *path = [NSString stringWithFormat:#"statuses/update.%#", API_FORMAT];
NSString *trimmedText = status;
if ([trimmedText length] > MAX_MESSAGE_LENGTH) {
trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:#"status"];
if (updateID > 0) {
[params setObject:[NSString stringWithFormat:#"%u", updateID] forKey:#"in_reply_to_status_id"];
}
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
queryParameters:params body:body
requestType:MGTwitterUpdateSendRequest
responseType:MGTwitterStatus];
}
TwitterPostViewController.m
- (IBAction)submitTweet{
[tweet resignFirstResponder];
if([[tweet text] length] > 0){
NSLog(#"%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"TwitterUsername"]);
NSLog(#"%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"TwitterPassword"]);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[engine sendUpdate:[tweet text]];
}
}
- (void)requestFailed:(NSString *)requestIdentifier withError:(NSError *)error{
NSLog(#"Fail: %#", error);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *failAlert;
if([error code] == 401){
failAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Incorrect Username & Password." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[failAlert setTag:10];
[failAlert setDelegate:self];
}
else
{
failAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed sending status to Twitter." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
[failAlert show];
[failAlert release];
}
It shows me the fail popup of Incorrect username and password
I have checked through nslog that username and password are going correct.
what could be wrong?
It looks like the version of MGTwitterEngine you're using is trying to use basic auth. That was switched off in Twitter in favour of OAuth. Get a newer version of MGTwitterEngine (or a fork that supports OAuth).

Facebook Graph API for iphone

check this Facebook GraphAPI
I am using this Graph API. It is not showing login screen every time ,I start this app.And I can see the results on console. I want to know how can I save result of method in NSDictionary to display it in tableView or some label..Method is
-(IBAction)getMeFeedButtonPressed:(id)sender {
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/feed" withGetVars:nil];
NSLog(#"getMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
}
Thanks in advance
I did this while using your kind-a stuff..
NSString *customString=[NSString stringWithFormat:#"me/feed"];
NSLog(#"here responce is for %#",customString);
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:customString withGetVars:nil];
NSLog(#"getMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
// [facebook_response ]
[parser release];
//NSString *feed;
// NSString *feed2;
NSMutableArray *feed =(NSMutableArray *) [facebook_response objectForKey:#"data"];
// NSMutableArray *feed1=(NSMutableArray *) [feed valueForKey:#"type"];
NSLog(#"%#",feed);
int index;
NSString* strMessage;
for (index=0; index<[feed count]; index++) {
//NSLog(#"........%#",[feed objectAtIndex:2]);
NSString* forTable=[feed objectAtIndex:index];
NSString *tempString = [forTable valueForKey:#"type"];
NSLog(#"--------%#",tempString);
if([tempString isEqualToString:#"status"]){
NSLog(#"do something with status");
strMessage=[forTable valueForKey:#"message"];
NSString* strTime =[forTable valueForKey:#"created_time"];
NSLog(#"\n %# \n %# ",strMessage,strTime);
[friendsArray addObject:strMessage];
}
else if([tempString isEqualToString:#"link"]){
NSLog(#"do something with link");
strMessage=[forTable valueForKey:#"message"];
NSString* nameStr =[forTable valueForKey:#"name"];
NSLog(#"\n %# \n %# ",strMessage,strTime);
[friendsArray addObject:strMessage];
[nameArray addObject:nameStr];
}
else if([tempString isEqualToString:#"photo"]){
NSLog(#"do something with photo");
strMessage=[forTable valueForKey:#"link"];
NSString* strTime =[forTable valueForKey:#"created_time"];
NSLog(#"\n %# \n %# ",strMessage,strTime);
[friendsArray addObject:strMessage];
}
else if([tempString isEqualToString:#"video"]){
NSLog(#"do something with video");
strMessage=[forTable valueForKey:#"name"];
NSString* strTime =[forTable valueForKey:#"created_time"];
NSLog(#"\n %# \n %# ",strMessage,strTime);
[friendsArray addObject:strMessage];
}
}
NSLog(#"%d",[friendsArray count]);
NSLog(#"%d",[friendsArray count]);
for(int i =0 ; i < [friendsArray count] ; i++)
{
NSLog(#"\nelement %d is :%#",i,[friendsArray objectAtIndex:i]);
}
FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:#"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.dummyArray=friendsArray;
detailViewController.dummyNameArray=nameArray;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
after doing this you will have all the data in Feed1. Now parse them according to your requirement of what you want to show in your table :)

TouchXML to read in twitter feed for iphone app

So I've managed to get the feed from twitter and am attempting to parse it...
I only require the following fields from the feed:
name, description, time_zone and created_at
I am successfully pulling out name and description.. however time_zone and created_at always are nil... The following is the code...
Anyone see why this might not be working?
-(void) friends_timeline_callback:(NSData *)data{
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#"Data from twitter: %#", string);
NSMutableArray *res = [[NSMutableArray alloc] init];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];
NSArray *nodes = nil;
//! searching for item nodes
nodes = [doc nodesForXPath:#"/statuses/status/user" error:nil];
for (CXMLElement *node in nodes)
{
int counter;
Contact *contact = [[Contact alloc] init];
for (counter = 0; counter < [node childCount]; counter++)
{
//pulling out name and description only for the minute!!!
if ([[[node childAtIndex:counter] name] isEqual:#"name"]){
contact.name = [[node childAtIndex:counter] stringValue];
}else if ([[[node childAtIndex:counter] name] isEqual:#"description"]) {
// common procedure: dictionary with keys/values from XML node
if ([[node childAtIndex:counter] stringValue] == NULL){
contact.nextAction = #"No description";
}else{
contact.nextAction = [[node childAtIndex:counter] stringValue];
}
}else if ([[[node childAtIndex:counter] name] isEqual:#"created_at"]){
contact.date == [[node childAtIndex:counter] stringValue];
}else if([[[node childAtIndex:counter] name] isEqual:#"time_zone"]){
contact.status == [[node childAtIndex:counter] stringValue];
[res addObject:contact];
[contact release];
}
}
}
self.contactsArray = res;
[res release];
[self.tableView reloadData];
}
Thanks in advance for your help!!
Fiona
Might be a mistake but why are they double equals (==), usually used for a condition check