Get Twitter Feed of particular user - iphone

Hii i am trying to get twitter feed of particular user..
My code:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:#"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jadoon88"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:response
options:0 error:&jsonParsingError];
NSLog(#"%#",publicTimeline);
Error:
errors = (
{
code = 215;
message = "Bad Authentication data";
}
);
i have searched in this site but do not get proper answer. Do i need to add any library?? and if anyone know about nice tutorial than it will be great

Related

getting error during json parsing

I am getting error during json parsing. When I trying to send the parameters using browser then it send me the success message that record store successfully. But when I send form parameters through iphone then i get nothing and in array i get NULL value.This is the json parsing code.
NSString *string1 = [[NSString alloc]initWithFormat:#"http://195.78.76.34/bedspace/mobileapi.php?action=save_room_info&Area=%#&Address=%#&Living_room=%#&Amenties=%#&Type_of_cost=%#&cost_of_room=%#&Security_deposit=%#&STLC=%#&Days_available=%#&Bill_included=%#&Broadband_available=%#&Exc_Smoke=%#&Exc_gender=%#&Exc_pets=%#&Exc_age=%#&Exc_language=%#&Exc_nationality=%#&Exc_Sexorientition=%#&Exc_intrest=%#&Pre_smoke=%#&Pre_gender=%#&Pre_occupation=%#&Pre_pets=%#&Pre_min_age=%#&Pre_max_age=%#&Pre_nationaltiy=%#&Pre_Language=%#&Pre_Sexorientition=%#&Misc=%#&Title=%#&Description=%#&Your_name=%#&Your_email=%#&Email_alert=%#&No_of_rooms=%#&Country=%#&City=%#&State=%#&Size_of_property=%#&Type_of_property=%#&Occupets_property=%#&My_property_status=%#&Amenties_two=%#&Size_of_room=%#&Refrence_required=%#",area,address,livingRoomVal,amenties,typeOfCost,costOfRoom,securityDeposit,STLC,daysAvailable,billsIncluded,broadbandAvailable,eSmoke,eGender,ePets,eAge,eLanguage,eNationality,eSexOrientation,eInterest,pSmoke,pGender,pOccupation,pPets,pMinAge,pMaxAge,pNationality,pLanguage,pSexOrientation,misc,title,description,yourName,yourEmail,emailAlerts,noOfRooms,country,city,state,sizeOfProperty,typeOfProperty,occupentsOfProperty,myPropertyStatus,amentiesTwo,sizeOfRoom,refrenceRequired];
NSLog(#"string 1 value %#",string1);
NSURL *urlRequest = [NSURL URLWithString:string1];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:urlRequest];
NSData *dataResponce = [NSURLConnection sendSynchronousRequest:request returningResponse:Nil error:Nil];
NSError *jsonParsingError = nil;
NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:dataResponce options:0 error:&jsonParsingError];
NSLog(#"get values %#",publicTimeline);
I don't know what the problem is. I also used SBJsonParser but i get nothing in array and after that I used NSJSONSerialization and same problem still happen i got nothing in NSData and in NSArray.
You cannot fill the URL with parameters and still expect it to be legal, so you need to URL Encode the URL before use:
NSURL *urlRequest = [NSURL URLWithString:[string1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Url links from database in iphone sdk

How to get urllink data that are stored in database in iphone sdk ?
Use the following Code may be help you.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"Your URL"]]];
// Perform request and get JSON as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(#"Your Data=%#",response);
id jsonObject = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil];

Get driving direction in iPhone

I read both iPhone and Google Map for iPhone EULA and want to implement a static driving direction map in my iPhone application (native).
I am finding a simple way to get route data and display with build-in route display feature in iOS 4 SDK' Mapkit.
Is there any programmer implement a feature like this with Google Map and Bing Map? Since Bing Map provided routing data in SOAP web service, it's seem easier to programming driving direction with Bing's service.
I found the solution for this. Just use a JSON parser to got google map API
For example:
NSDictionary *testJsondata = [self testJson:GoogleMapXMLDirectionQueryString];
NSLog(#"Here is the title of the response: %#", [testJsondata valueForKey:#"status"]);
for (id key in testJsondata) {
NSLog(#"key: %#, value: %#", key, [testJsondata objectForKey:key]);
}
}
- (NSDictionary *) testJson : (NSString*) url
{
id response = [self objectWithUrl:[NSURL URLWithString:url]];
NSDictionary *feed = (NSDictionary *)response;
return feed;
}
- (id) objectWithUrl:(NSURL *)url
{
SBJsonParser *jsonParser = [SBJsonParser new];
NSString *jsonString = [self stringWithUrl:url];
// Parse the JSON into an Object
return [jsonParser objectWithString:jsonString error:NULL];
}
- (NSString *)stringWithUrl:(NSURL *)url
{
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse: &response
error: &error];
// Construct a String around the Data from the response
return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
}
- (NSString *)getDirectionInXML:(NSString *)GoogleMapXMLDirectionQueryString
{
NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString: [NSString stringWithFormat:GoogleMapXMLDirectionQueryString]]];
[request setHTTPMethod: #"GET"];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
return stringReply;
}

Twitter oauth problem with frindship/create in api

I am using Google Data API sample touch application, which is available at code.google....
I am having a problem can any one help.
Please tell me if I am doing some thing wrong.
The user who has loged in has to follow some person XYZ (just using
XYZ for security purpose).
I am using the URL
urlStr = #"http://api.twitter.com/1/friendships/create/XYZ.xml";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url];
//made post as requested in twitter API
[request setHTTPMethod:#"POST"];
ConnectAppDelegate *appDelegate = (ConnectAppDelegate *)
[[UIApplication sharedApplication] delegate];
[mAouth authorizeRequest:request];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
if (data) {
// API fetch succeeded
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"API response: %#", str);
} else {
// fetch failed
NSLog(#"API fetch error: %#", error);
}
In the response I get
http://api.twitter.com/1/friendships/create/XYZ.xml
2010-06-11 16:04:39.437 Connect[4265:20b] API response:
<?xml
version="1.0" encoding="UTF-8"?>
<hash>
<request>/1/friendships/create/XYZ.xml</request>
<error>Invalid / used nonce</error>
</hash>
This error can happen if your time and the server time are more than 5 mins different, check that your server / pc has the same time as the server.

Iphone Caching Problem

when I call
-(IBAction)goback:(id)sender
{
NSURL *xmlURL=[NSURL URLWithString:#"http://demo.komexa.com/sicherungsbereich.xml"];
NSURLRequest *request = [NSURLRequest requestWithURL:xmlURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:2];
NSURLResponse *theResponse;
NSError *theError;
NSData *myRequestResult = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
NSString *stringReply = (NSString *)[[NSString alloc] initWithData:myRequestResult encoding:NSUTF8StringEncoding];
NSLog(#"reply from server: %#", stringReply);
}
with the Iphone , on the simulator it loads the String everytime really from the internet.But on the devices, it caches the String, so even if the content of http://demo.komexa.com/sicherungsbereich.xml changes (you can do that by calling http://demo.komexa.com) the String does not automatically reload new data.
Have you got an Idea?
I have uploaded the Code here,because of formatting problems:
http://demo.komexa.com/problem.txt
just generate a random number and pass with your url , you get required result
e.g:
int randomNumber1 = 1 + arc4random()% 9;
NSString *rstr = [NSString stringWithFormat: #"%d",randomNumber1];
NSString *address = #"http://www.socialfactory.net/client-app/photovote/get_data.php";
NSString * nstr=[NSString stringWithFormat:#"%#?t=%#",address,rstr];
//NSURLRequest *theRequest=nil;
NSURLRequest * theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:nstr]];
NSURLResponse *resp = nil;
NSError *err = nil;
Maybe your Simulator and iPhone have different proxie settings. check this or try with the NSURLRequestReloadIgnoringLocalAndRemoteCacheData policy which also ignores intermediate cachings. See the docs here.